From f358f185e00bf92bf2095b1eebcc4c950588488d Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 6 May 2017 12:49:39 -0400 Subject: Fixing bug with 'has' and 'datasource' around referencing sub-maps in nested maps Signed-off-by: Dave Henderson --- test/integration/datasources_file.bats | 12 ++++++------ test/integration/typeconv_funcs.bats | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test/integration/typeconv_funcs.bats (limited to 'test') diff --git a/test/integration/datasources_file.bats b/test/integration/datasources_file.bats index 1a3ad824..9e22a834 100644 --- a/test/integration/datasources_file.bats +++ b/test/integration/datasources_file.bats @@ -13,17 +13,17 @@ function teardown () { } @test "supports json datasource file" { - echo '{"foo": "bar"}' > $tmpdir/config.json - gomplate -d config=$tmpdir/config.json -i '{{(datasource "config").foo}}' + echo '{"foo": {"bar": "baz"}}' > $tmpdir/config.json + gomplate -d config=$tmpdir/config.json -i '{{(datasource "config").foo.bar}}' [ "$status" -eq 0 ] - [[ "${output}" == "bar" ]] + [[ "${output}" == "baz" ]] } @test "supports YAML datasource file" { - echo 'foo: bar' > $tmpdir/config.yml - gomplate -d config=$tmpdir/config.yml -i '{{(datasource "config").foo}}' + echo -e 'foo:\n bar: baz' > $tmpdir/config.yml + gomplate -d config=$tmpdir/config.yml -i '{{(datasource "config").foo.bar}}' [ "$status" -eq 0 ] - [[ "${output}" == "bar" ]] + [[ "${output}" == "baz" ]] } @test "ds alias" { diff --git a/test/integration/typeconv_funcs.bats b/test/integration/typeconv_funcs.bats new file mode 100644 index 00000000..9127915e --- /dev/null +++ b/test/integration/typeconv_funcs.bats @@ -0,0 +1,19 @@ +#!/usr/bin/env bats + +load helper + +tmpdir=$(mktemp -u) + +function setup () { + mkdir -p $tmpdir +} + +function teardown () { + rm -rf $tmpdir || true +} + +@test "'has' can handle sub-maps in nested maps" { + gomplate -d config=$tmpdir/config.yml -i '{{ has ("foo:\n bar:\n baz: qux" | yaml).foo.bar "baz"}}' + [ "$status" -eq 0 ] + [[ "${output}" == "true" ]] +} -- cgit v1.2.3