core: Skip NoOp changes in legacyDiffComparisonString

This (along with some other minor adjustments) fixes
TestContext2Apply_countDecreaseToOneCorrupted.
This commit is contained in:
Martin Atkins 2018-09-18 15:37:04 -07:00
parent 3b89930f6f
commit 19a3095c0d
3 changed files with 15 additions and 4 deletions

View File

@ -2255,8 +2255,9 @@ func TestContext2Apply_countDecreaseToOneCorrupted(t *testing.T) {
if p, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
} else {
planStr := legacyPlanComparisonString(ctx.State(), p.Changes)
if got, want := planStr, testTerraformApplyCountDecToOneCorruptedPlanStr; got != want {
got := strings.TrimSpace(legacyPlanComparisonString(ctx.State(), p.Changes))
want := strings.TrimSpace(testTerraformApplyCountDecToOneCorruptedPlanStr)
if got != want {
t.Fatalf("wrong plan result\ngot:\n%s\nwant:\n%s", got, want)
}
}
@ -2269,7 +2270,7 @@ func TestContext2Apply_countDecreaseToOneCorrupted(t *testing.T) {
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testTerraformApplyCountDecToOneCorruptedStr)
if actual != expected {
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
t.Fatalf("wrong final state\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
}
}

View File

@ -830,6 +830,11 @@ func legacyDiffComparisonString(changes *plans.Changes) string {
resourceKeys := map[string][]string{}
var moduleKeys []string
for _, rc := range changes.Resources {
if rc.Action == plans.NoOp {
// We won't mention no-op changes here at all, since the old plan
// model we are emulating here didn't have such a concept.
continue
}
moduleKey := rc.Addr.Module.String()
if _, exists := byModule[moduleKey]; !exists {
moduleKeys = append(moduleKeys, moduleKey)

View File

@ -466,6 +466,7 @@ aws_instance.foo:
const testTerraformApplyCountDecToOneCorruptedStr = `
aws_instance.foo:
ID = bar
provider = provider.aws
foo = foo
type = aws_instance
`
@ -473,16 +474,20 @@ aws_instance.foo:
const testTerraformApplyCountDecToOneCorruptedPlanStr = `
DIFF:
DESTROY: aws_instance.foo.0
DESTROY: aws_instance.foo[0]
STATE:
aws_instance.foo:
ID = bar
provider = provider.aws
foo = foo
type = aws_instance
aws_instance.foo.0:
ID = baz
provider = provider.aws
type = aws_instance
`