core: Fix TestContext2Apply_countTainted

The prior behavior being asserted by this test was incorrect, since the
configuration calls for there to be two instances of the resource at the
end.

We also now assert on the generated plan since it's important to verify
that we are indeed planning to replace the zeroth instance but not the
first instance (which doesn't yet exist).
This commit is contained in:
Martin Atkins 2018-09-25 17:09:23 -07:00
parent 3e9d23b120
commit 90faaf9f80
2 changed files with 31 additions and 11 deletions

View File

@ -2380,19 +2380,43 @@ func TestContext2Apply_countTainted(t *testing.T) {
State: s,
})
if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("plan errors: %s", diags.Err())
{
plan, diags := ctx.Plan()
assertNoErrors(t, diags)
got := strings.TrimSpace(legacyDiffComparisonString(plan.Changes))
want := strings.TrimSpace(`
DESTROY/CREATE: aws_instance.foo[0]
foo: "foo" => "foo"
id: "bar" => "<computed>"
type: "aws_instance" => "aws_instance"
CREATE: aws_instance.foo[1]
foo: "" => "foo"
id: "" => "<computed>"
type: "" => "aws_instance"
`)
if got != want {
t.Fatalf("wrong plan\n\ngot:\n%s\n\nwant:\n%s", got, want)
}
}
state, diags := ctx.Apply()
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
assertNoErrors(t, diags)
got := strings.TrimSpace(state.String())
want := strings.TrimSpace(testTerraformApplyCountTaintedStr)
want := strings.TrimSpace(`
aws_instance.foo.0:
ID = foo
provider = provider.aws
foo = foo
type = aws_instance
aws_instance.foo.1:
ID = foo
provider = provider.aws
foo = foo
type = aws_instance
`)
if got != want {
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", got, want)
t.Fatalf("wrong final state\n\ngot:\n%s\n\nwant:\n%s", got, want)
}
}

View File

@ -492,10 +492,6 @@ aws_instance.foo.0:
type = aws_instance
`
const testTerraformApplyCountTaintedStr = `
<no state>
`
const testTerraformApplyCountVariableStr = `
aws_instance.foo.0:
ID = foo