From 082cba0a81c7d87b7fb7310c6bf65e4e4179d04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Fri, 28 Apr 2017 18:06:28 +0200 Subject: 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 --- test/files/input-dir/config.yml | 2 + test/files/input-dir/in/inner/nested.txt | 1 + test/files/input-dir/in/top.txt | 1 + test/integration/input-dir.bats | 69 ++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 test/files/input-dir/config.yml create mode 100644 test/files/input-dir/in/inner/nested.txt create mode 100644 test/files/input-dir/in/top.txt create mode 100644 test/integration/input-dir.bats (limited to 'test') 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" ]] +} -- cgit v1.2.3