Skip to content

Commit

Permalink
decoder_test check for decodedFields and unusedKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Apr 5, 2019
1 parent 65a6292 commit 258b882
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
34 changes: 34 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,40 @@ func TestDecode_structureMapInvalid(t *testing.T) {
}
}

func TestDecode_structureMapExtraKeys(t *testing.T) {
type hclVariable struct {
A int
B int
Found []string `hcl:",decodedFields"`
Extra []string `hcl:",unusedKeys"`
}

q := hclVariable{
A: 1,
B: 2,
Found: []string{"A", "B"},
Extra: []string{"extra1", "extra2"},
}

var p hclVariable
ast, _ := Parse(testReadFile(t, "structure_map_extra_keys.hcl"))
DecodeObject(&p, ast)
if !(p.A == q.A && p.B == q.B &&
reflect.DeepEqual(p.Found, q.Found) &&
reflect.DeepEqual(p.Extra, q.Extra)) {
t.Fatal("not equal")
}

var j hclVariable
ast, _ = Parse(testReadFile(t, "structure_map_extra_keys.json"))
DecodeObject(&j, ast)
if !(j.A == q.A && j.B == q.B &&
reflect.DeepEqual(j.Found, q.Found) &&
reflect.DeepEqual(j.Extra, q.Extra)) {
t.Fatal("not equal")
}
}

func TestDecode_interfaceNonPointer(t *testing.T) {
var value interface{}
err := Decode(value, testReadFile(t, "basic_int_string.hcl"))
Expand Down
4 changes: 4 additions & 0 deletions test-fixtures/structure_map_extra_keys.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a = 1
b = 2
extra1 = 3
extra2 = 4
6 changes: 6 additions & 0 deletions test-fixtures/structure_map_extra_keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"a": 1,
"b": 2,
"extra1": 3,
"extra2": 4
}

0 comments on commit 258b882

Please sign in to comment.