summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRoland Huß <roland@ro14nd.de>2017-04-28 18:06:28 +0200
committerDave Henderson <dhenderson@gmail.com>2017-04-28 12:06:28 -0400
commit082cba0a81c7d87b7fb7310c6bf65e4e4179d04a (patch)
treeeefd99e72387628ff3c9aca8f680adde66084bc2 /test
parent5649b5bf144156dafebe0e1a0cbf694e222f1391 (diff)
Add --input-dir and --output-dir as options (#119)
All filese from --input-dir will be processed as templates and stored with the same directory hierachy in --ouput-dir - Use both options when a whole directory hierarchy needs to be processed. - Extracted file processing logic in an extra process.go - --output-dir is optional and default to "." - --output-dir is created automatically if not existing Fixes #117 Signed-off-by: Roland Huss <roland@ro14nd.de>
Diffstat (limited to 'test')
-rw-r--r--test/files/input-dir/config.yml2
-rw-r--r--test/files/input-dir/in/inner/nested.txt1
-rw-r--r--test/files/input-dir/in/top.txt1
-rw-r--r--test/integration/input-dir.bats69
4 files changed, 73 insertions, 0 deletions
diff --git a/test/files/input-dir/config.yml b/test/files/input-dir/config.yml
new file mode 100644
index 00000000..1ec99548
--- /dev/null
+++ b/test/files/input-dir/config.yml
@@ -0,0 +1,2 @@
+one: eins
+two: zwei
diff --git a/test/files/input-dir/in/inner/nested.txt b/test/files/input-dir/in/inner/nested.txt
new file mode 100644
index 00000000..55e06b79
--- /dev/null
+++ b/test/files/input-dir/in/inner/nested.txt
@@ -0,0 +1 @@
+{{ (datasource "config").two }} \ No newline at end of file
diff --git a/test/files/input-dir/in/top.txt b/test/files/input-dir/in/top.txt
new file mode 100644
index 00000000..9069510b
--- /dev/null
+++ b/test/files/input-dir/in/top.txt
@@ -0,0 +1 @@
+{{ (datasource "config").one }} \ No newline at end of file
diff --git a/test/integration/input-dir.bats b/test/integration/input-dir.bats
new file mode 100644
index 00000000..72667a29
--- /dev/null
+++ b/test/integration/input-dir.bats
@@ -0,0 +1,69 @@
+#!/usr/bin/env bats
+
+load helper
+
+tmpdir=$(mktemp -u)
+
+function setup () {
+ mkdir -p $tmpdir
+ mkdir -p $tmpdir/in/inner
+ echo -n "{{ (datasource \"config\").one }}" > $tmpdir/in/eins.txt
+ echo -n "{{ (datasource \"config\").two }}" > $tmpdir/in/inner/deux.txt
+
+ cat <<"EOT" > $tmpdir/config.yml
+one: eins
+two: deux
+EOT
+}
+
+function teardown () {
+ # rm -rf $tmpdir
+ echo
+}
+
+@test "takes --input-dir and produces proper output files" {
+ rm -rf $tmpdir/out || true
+ gomplate --input-dir $tmpdir/in --output-dir $tmpdir/out -d config=$tmpdir/config.yml
+ [ "$status" -eq 0 ]
+ [[ "$(ls $tmpdir/out | wc -l)" == 2 ]]
+ [[ "$(ls $tmpdir/out/inner | wc -l)" == 1 ]]
+ [[ "$(cat $tmpdir/out/eins.txt)" == "eins" ]]
+ [[ "$(cat $tmpdir/out/inner/deux.txt)" == "deux" ]]
+}
+
+@test "test . as default --output-dir param" {
+ rm -rf $tmpdir/out_dot || true
+ mkdir -p $tmpdir/out_dot
+ g=$(pwd)/bin/gomplate
+ cd $tmpdir/out_dot
+ run $g --input-dir $tmpdir/in -d config=$tmpdir/config.yml
+ [ "$?" -eq 0 ]
+ [[ "$(ls | wc -l)" == 2 ]]
+ [[ "$(ls inner | wc -l)" == 1 ]]
+ [[ "$(cat eins.txt)" == "eins" ]]
+ [[ "$(cat inner/deux.txt)" == "deux" ]]
+}
+
+@test "errors given --output-dir but no --input-dir" {
+ gomplate --output-dir "."
+ [ "$status" -eq 1 ]
+ [[ "${output}" == "--input-dir must be set when --output-dir is set" ]]
+}
+
+@test "errors given both --input-dir and --in" {
+ gomplate --input-dir "." --in "param"
+ [ "$status" -eq 1 ]
+ [[ "${output}" == "--input-dir can not be used together with --in or --file" ]]
+}
+
+@test "errors given both --input-dir and --file" {
+ gomplate --input-dir "." --file input.txt
+ [ "$status" -eq 1 ]
+ [[ "${output}" == "--input-dir can not be used together with --in or --file" ]]
+}
+
+@test "errors given both --output-dir and --out" {
+ gomplate --input-dir "." --output-dir /tmp --out out
+ [ "$status" -eq 1 ]
+ [[ "${output}" == "--out can not be used together with --output-dir" ]]
+}