From d48f3600fe38a09672f4c3e5affd365ad55f349c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 14 Sep 2018 09:31:46 -0700 Subject: [PATCH] states: In Module.testString, use incrementing ids for deposed In our old world we always used 1-based indices into a slice of deposed objects. The new models instead use a map keyed by pseudorandom strings, so that deposed objects will have a consistent identity across multiple operations. However, having that pseudo-random string in our test comparison output is not helpful, since such strings can never match hard-coded expectation strings. Therefore for the purposes of generating this test comparison output we'll revert back to using 1-based indexes. This should avoid problems for tests that only create one deposed object per instance, but those which create more than one will need to do some more work since the _ordering_ of these objects in the output is still pseudorandom as a result of it coming from a map rather than a slice. --- states/state_string.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/states/state_string.go b/states/state_string.go index f9202f820..a2ee9a25f 100644 --- a/states/state_string.go +++ b/states/state_string.go @@ -182,13 +182,15 @@ func (m *Module) testString() string { // CAUTION: Since deposed keys are now random strings instead of // incrementing integers, this result will not be deterministic // if there is more than one deposed object. - for k, t := range is.Deposed { + i := 1 + for _, t := range is.Deposed { id := legacyInstanceObjectID(t) taintStr := "" if t.Status == ObjectTainted { taintStr = " (tainted)" } - buf.WriteString(fmt.Sprintf(" Deposed ID %s = %s%s\n", k, id, taintStr)) + buf.WriteString(fmt.Sprintf(" Deposed ID %d = %s%s\n", i, id, taintStr)) + i++ } if obj := is.Current; obj != nil && len(obj.Dependencies) > 0 {