remove empty flatmap containers from test states

Don't compare attributes with zero-length flatmap continers in tests.
This commit is contained in:
James Bardin 2018-12-04 15:42:33 -05:00
parent 7f9d76cbf5
commit 547d63bcde
1 changed files with 22 additions and 1 deletions

View File

@ -91,7 +91,10 @@ func testStepImportState(
return state, stepDiags.Err() return state, stepDiags.Err()
} }
newState := mustShimNewState(importedState, schemas) newState, err := shimNewState(importedState, schemas)
if err != nil {
return nil, err
}
// Go through the new state and verify // Go through the new state and verify
if step.ImportStateCheck != nil { if step.ImportStateCheck != nil {
@ -127,13 +130,31 @@ func testStepImportState(
r.Primary.ID) r.Primary.ID)
} }
// don't add empty flatmapped containers, so we can more easily
// compare the attributes
skipEmpty := func(k, v string) bool {
if strings.HasSuffix(k, ".#") || strings.HasSuffix(k, ".%") {
if v == "0" {
return true
}
}
return false
}
// Compare their attributes // Compare their attributes
actual := make(map[string]string) actual := make(map[string]string)
for k, v := range r.Primary.Attributes { for k, v := range r.Primary.Attributes {
if skipEmpty(k, v) {
continue
}
actual[k] = v actual[k] = v
} }
expected := make(map[string]string) expected := make(map[string]string)
for k, v := range oldR.Primary.Attributes { for k, v := range oldR.Primary.Attributes {
if skipEmpty(k, v) {
continue
}
expected[k] = v expected[k] = v
} }