From e5d4045cf0d1370190f185520b85c035ec9af83e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 9 Nov 2015 20:02:20 -0800 Subject: [PATCH] Test for GH-46 --- decoder_test.go | 42 ++++++++++++++++++++++++++++++++++ test-fixtures/slice_expand.hcl | 7 ++++++ 2 files changed, 49 insertions(+) create mode 100644 test-fixtures/slice_expand.hcl diff --git a/decoder_test.go b/decoder_test.go index 3bf0ed9..5979baf 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -440,6 +440,48 @@ func TestDecode_structureArray(t *testing.T) { } } +func TestDecode_sliceExpand(t *testing.T) { + type testInner struct { + Name string `hcl:",key"` + Key string + } + + type testStruct struct { + Services []testInner `hcl:"service,expand"` + } + + expected := testStruct{ + Services: []testInner{ + testInner{ + Name: "my-service-0", + Key: "value", + }, + testInner{ + Name: "my-service-1", + Key: "value", + }, + }, + } + + files := []string{ + "slice_expand.hcl", + } + + for _, f := range files { + t.Logf("Testing: %s", f) + + var actual testStruct + err := Decode(&actual, testReadFile(t, f)) + if err != nil { + t.Fatalf("Input: %s\n\nerr: %s", f, err) + } + + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("Input: %s\n\nActual: %#v\n\nExpected: %#v", f, actual, expected) + } + } +} + func TestDecode_structureMap(t *testing.T) { // This test is extracted from a failure in Terraform (terraform.io), // hence the interesting structure naming. diff --git a/test-fixtures/slice_expand.hcl b/test-fixtures/slice_expand.hcl new file mode 100644 index 0000000..4d3725f --- /dev/null +++ b/test-fixtures/slice_expand.hcl @@ -0,0 +1,7 @@ +service "my-service-0" { + key = "value" +} + +service "my-service-1" { + key = "value" +}