fix the test that was supposed to break

The test for this behavior did not work, because the old mock diff
function does not work correctly. Write a PlanResourceChange function to
return a correct plan.
This commit is contained in:
James Bardin 2020-10-02 08:50:24 -04:00
parent 07af1c6225
commit 43c0525277
1 changed files with 27 additions and 16 deletions

View File

@ -11389,11 +11389,34 @@ locals {
return testApplyFn(info, s, d) return testApplyFn(info, s, d)
} }
p.DiffFn = testDiffFn p.PlanResourceChangeFn = func(r providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
n := r.ProposedNewState.AsValueMap()
if r.PriorState.IsNull() {
n["id"] = cty.UnknownVal(cty.String)
resp.PlannedState = cty.ObjectVal(n)
return resp
}
p := r.PriorState.AsValueMap()
priorRN := p["require_new"]
newRN := n["require_new"]
if eq := priorRN.Equals(newRN); !eq.IsKnown() || eq.False() {
resp.RequiresReplace = []cty.Path{{cty.GetAttrStep{Name: "require_new"}}}
n["id"] = cty.UnknownVal(cty.String)
}
resp.PlannedState = cty.ObjectVal(n)
return resp
}
// reduce the count to 1
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Variables: InputValues{ Variables: InputValues{
"ct": &InputValue{ "ct": &InputValue{
Value: cty.NumberIntVal(0), Value: cty.NumberIntVal(1),
SourceType: ValueFromCaller, SourceType: ValueFromCaller,
}, },
}, },
@ -11409,21 +11432,11 @@ locals {
t.Fatal(diags.ErrWithWarnings()) t.Fatal(diags.ErrWithWarnings())
} }
// if resource b isn't going to apply correctly, we will get an error about
// an invalid plan value
state, diags = ctx.Apply() state, diags = ctx.Apply()
errMsg := diags.ErrWithWarnings().Error() if diags.HasErrors() {
if strings.Contains(errMsg, "Cycle") { log.Fatal(diags.ErrWithWarnings())
t.Fatal("test should not produce a cycle:\n", errMsg)
} }
if !diags.HasErrors() {
// FIXME: this test is correct, but needs to wait until we no longer
// evaluate resourced that are pending destruction.
t.Fatal("used to error, but now it's fixed!")
}
return
// check the output, as those can't cause an error planning the value // check the output, as those can't cause an error planning the value
out := state.RootModule().OutputValues["out"].Value.AsString() out := state.RootModule().OutputValues["out"].Value.AsString()
if out != "a0" { if out != "a0" {
@ -11450,8 +11463,6 @@ locals {
t.Fatal(diags.ErrWithWarnings()) t.Fatal(diags.ErrWithWarnings())
} }
// if resource b isn't going to apply correctly, we will get an error about
// an invalid plan value
state, diags = ctx.Apply() state, diags = ctx.Apply()
if diags.HasErrors() { if diags.HasErrors() {
t.Fatal(diags.ErrWithWarnings()) t.Fatal(diags.ErrWithWarnings())