From a4f0365393dbc1085486b811f2075bac2a5fd15d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Aug 2014 14:19:23 -0700 Subject: [PATCH] Failing test --- decoder_test.go | 42 +++++++++++++++++++++++++++ test-fixtures/decode_tf_variable.hcl | 10 +++++++ test-fixtures/decode_tf_variable.json | 14 +++++++++ 3 files changed, 66 insertions(+) create mode 100644 test-fixtures/decode_tf_variable.hcl create mode 100644 test-fixtures/decode_tf_variable.json 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" + } + } + } +}