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:
parent
3e9d23b120
commit
90faaf9f80
|
@ -2380,19 +2380,43 @@ func TestContext2Apply_countTainted(t *testing.T) {
|
||||||
State: s,
|
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()
|
state, diags := ctx.Apply()
|
||||||
if diags.HasErrors() {
|
assertNoErrors(t, diags)
|
||||||
t.Fatalf("diags: %s", diags.Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
got := strings.TrimSpace(state.String())
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -492,10 +492,6 @@ aws_instance.foo.0:
|
||||||
type = aws_instance
|
type = aws_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
const testTerraformApplyCountTaintedStr = `
|
|
||||||
<no state>
|
|
||||||
`
|
|
||||||
|
|
||||||
const testTerraformApplyCountVariableStr = `
|
const testTerraformApplyCountVariableStr = `
|
||||||
aws_instance.foo.0:
|
aws_instance.foo.0:
|
||||||
ID = foo
|
ID = foo
|
||||||
|
|
Loading…
Reference in New Issue