diff --git a/decoder_test.go b/decoder_test.go index 9ea9621..7ec4225 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -238,3 +238,45 @@ func TestDecode_structureArray(t *testing.T) { } } } + +func TestDecode_structureMap(t *testing.T) { + // This test is extracted from a failure in Terraform (terraform.io), + // hence the interesting structure naming. + + type hclVariable struct { + Default interface{} + Description string + Fields []string `hcl:",decodedFields"` + } + + type rawConfig struct { + Variable map[string]hclVariable + } + + expected := rawConfig{ + Variable: map[string]hclVariable{ + "foo": hclVariable{ + Default: "bar", + Description: "bar", + }, + }, + } + + files := []string{ + //"decode_tf_variable.hcl", + "decode_tf_variable.json", + } + + for _, f := range files { + var actual rawConfig + + err := Decode(&actual, testReadFile(t, f)) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("Input: %s\n\nActual: %#v\n\nExpected: %#v", f, actual, expected) + } + } +} diff --git a/test-fixtures/decode_tf_variable.hcl b/test-fixtures/decode_tf_variable.hcl new file mode 100644 index 0000000..52dcaa1 --- /dev/null +++ b/test-fixtures/decode_tf_variable.hcl @@ -0,0 +1,10 @@ +variable "foo" { + default = "bar" + description = "bar" +} + +variable "amis" { + default = { + east = "foo" + } +} diff --git a/test-fixtures/decode_tf_variable.json b/test-fixtures/decode_tf_variable.json new file mode 100644 index 0000000..49f921e --- /dev/null +++ b/test-fixtures/decode_tf_variable.json @@ -0,0 +1,14 @@ +{ + "variable": { + "foo": { + "default": "bar", + "description": "bar" + }, + + "amis": { + "default": { + "east": "foo" + } + } + } +}