From 547d63bcdebab6923b50f8349417848f67525458 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 4 Dec 2018 15:42:33 -0500 Subject: [PATCH] remove empty flatmap containers from test states Don't compare attributes with zero-length flatmap continers in tests. --- helper/resource/testing_import_state.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/helper/resource/testing_import_state.go b/helper/resource/testing_import_state.go index a235904b7..b5b774b09 100644 --- a/helper/resource/testing_import_state.go +++ b/helper/resource/testing_import_state.go @@ -91,7 +91,10 @@ func testStepImportState( 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 if step.ImportStateCheck != nil { @@ -127,13 +130,31 @@ func testStepImportState( 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 actual := make(map[string]string) for k, v := range r.Primary.Attributes { + if skipEmpty(k, v) { + continue + } actual[k] = v } + expected := make(map[string]string) for k, v := range oldR.Primary.Attributes { + if skipEmpty(k, v) { + continue + } expected[k] = v }