Add test for ResourceConfig.Get
ResourceConfig.Get could previously return (nil, true) when looking up an interpolated map in a list because of the indexing ambiguity. Make sure we test that a non-existent value always returns false.
This commit is contained in:
parent
68ba2d6ff0
commit
8f6583c264
|
@ -160,6 +160,18 @@ func TestResourceConfigGet(t *testing.T) {
|
||||||
Key: "mapname.0.listkey.0.key",
|
Key: "mapname.0.listkey.0.key",
|
||||||
Value: 3,
|
Value: 3,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// A map assigned to a list via interpolation should Get a non-existent
|
||||||
|
// value. The test code now also checks that Get doesn't return (nil,
|
||||||
|
// true), which it previously did for this configuration.
|
||||||
|
{
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"maplist": "${var.maplist}",
|
||||||
|
},
|
||||||
|
Key: "maplist.0",
|
||||||
|
Value: nil,
|
||||||
|
},
|
||||||
|
|
||||||
// FIXME: this is ambiguous, and matches the nested map
|
// FIXME: this is ambiguous, and matches the nested map
|
||||||
// leaving here to catch this behaviour if it changes.
|
// leaving here to catch this behaviour if it changes.
|
||||||
{
|
{
|
||||||
|
@ -226,7 +238,11 @@ func TestResourceConfigGet(t *testing.T) {
|
||||||
|
|
||||||
// Test getting a key
|
// Test getting a key
|
||||||
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
t.Run(fmt.Sprintf("get-%d", i), func(t *testing.T) {
|
||||||
v, _ := rc.Get(tc.Key)
|
v, ok := rc.Get(tc.Key)
|
||||||
|
if ok && v == nil {
|
||||||
|
t.Fatal("(nil, true) returned from Get")
|
||||||
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(v, tc.Value) {
|
if !reflect.DeepEqual(v, tc.Value) {
|
||||||
t.Fatalf("%d bad: %#v", i, v)
|
t.Fatalf("%d bad: %#v", i, v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue