Set and single test coverage

This commit is contained in:
Pam Selle 2020-10-15 17:25:53 -04:00
parent a5c5d2c28c
commit a1a46425bd
2 changed files with 26 additions and 5 deletions

View File

@ -974,15 +974,12 @@ func getValMarks(schema *configschema.Block, val cty.Value, path cty.Path) []cty
switch blockS.Nesting { switch blockS.Nesting {
case configschema.NestingSingle, configschema.NestingGroup: case configschema.NestingSingle, configschema.NestingGroup:
pvm = append(pvm, getValMarks(&blockS.Block, blockV, blockPath)...) pvm = append(pvm, getValMarks(&blockS.Block, blockV, blockPath)...)
case configschema.NestingList, configschema.NestingMap: case configschema.NestingList, configschema.NestingMap, configschema.NestingSet:
for it := blockV.ElementIterator(); it.Next(); { for it := blockV.ElementIterator(); it.Next(); {
idx, blockEV := it.Element() idx, blockEV := it.Element()
morePaths := getValMarks(&blockS.Block, blockEV, append(blockPath, cty.IndexStep{Key: idx})) morePaths := getValMarks(&blockS.Block, blockEV, append(blockPath, cty.IndexStep{Key: idx}))
pvm = append(pvm, morePaths...) pvm = append(pvm, morePaths...)
} }
case configschema.NestingSet:
// TODO
continue
default: default:
panic(fmt.Sprintf("unsupported nesting mode %s", blockS.Nesting)) panic(fmt.Sprintf("unsupported nesting mode %s", blockS.Nesting))
} }

View File

@ -135,7 +135,7 @@ func TestEvaluatorGetResource(t *testing.T) {
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
&states.ResourceInstanceObjectSrc{ &states.ResourceInstanceObjectSrc{
Status: states.ObjectReady, Status: states.ObjectReady,
AttrsJSON: []byte(`{"id":"foo", "nesting_list": [{"sensitive_value":"abc"}], "nesting_map": {"foo":{"foo":"x"}}, "value":"hello"}`), AttrsJSON: []byte(`{"id":"foo", "nesting_list": [{"sensitive_value":"abc"}], "nesting_map": {"foo":{"foo":"x"}}, "nesting_set": [{"baz":"abc"}], "nesting_single": {"boop":"abc"}, "value":"hello"}`),
}, },
addrs.AbsProviderConfig{ addrs.AbsProviderConfig{
Provider: addrs.NewDefaultProvider("test"), Provider: addrs.NewDefaultProvider("test"),
@ -206,6 +206,22 @@ func TestEvaluatorGetResource(t *testing.T) {
}, },
Nesting: configschema.NestingMap, Nesting: configschema.NestingMap,
}, },
"nesting_set": {
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"baz": {Type: cty.String, Optional: true, Sensitive: true},
},
},
Nesting: configschema.NestingSet,
},
"nesting_single": {
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"boop": {Type: cty.String, Optional: true, Sensitive: true},
},
},
Nesting: configschema.NestingSingle,
},
}, },
}, },
}, },
@ -230,6 +246,14 @@ func TestEvaluatorGetResource(t *testing.T) {
"nesting_map": cty.MapVal(map[string]cty.Value{ "nesting_map": cty.MapVal(map[string]cty.Value{
"foo": cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("x").Mark("sensitive")}), "foo": cty.ObjectVal(map[string]cty.Value{"foo": cty.StringVal("x").Mark("sensitive")}),
}), }),
"nesting_set": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"baz": cty.StringVal("abc").Mark("sensitive"),
}),
}),
"nesting_single": cty.ObjectVal(map[string]cty.Value{
"boop": cty.StringVal("abc").Mark("sensitive"),
}),
"value": cty.StringVal("hello").Mark("sensitive"), "value": cty.StringVal("hello").Mark("sensitive"),
}) })