add failing test, and start new test files
The existing context test files are becoming quite unwieldy. Start new ones both to make editing easier, and to help discourage the copy+pasting of older test patterns we no longer need.
This commit is contained in:
parent
08560ee77a
commit
e4e50617aa
|
@ -0,0 +1 @@
|
||||||
|
package terraform
|
|
@ -12564,3 +12564,8 @@ resource "test_object" "a" {
|
||||||
t.Fatalf("error missing expected info: %q", errString)
|
t.Fatalf("error missing expected info: %q", errString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// NOTE: Due to the size of this file, new tests should be added to
|
||||||
|
// context_apply2_test.go.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package terraform
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/addrs"
|
||||||
|
"github.com/hashicorp/terraform/plans"
|
||||||
|
"github.com/hashicorp/terraform/providers"
|
||||||
|
"github.com/hashicorp/terraform/states"
|
||||||
|
"github.com/zclconf/go-cty/cty"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestContext2Plan_removedDuringRefresh(t *testing.T) {
|
||||||
|
// The resource was added to state but actually failed to create and was
|
||||||
|
// left tainted. This should be removed during plan and result in a Create
|
||||||
|
// action.
|
||||||
|
m := testModuleInline(t, map[string]string{
|
||||||
|
"main.tf": `
|
||||||
|
resource "test_object" "a" {
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
p := simpleMockProvider()
|
||||||
|
p.ReadResourceFn = func(req providers.ReadResourceRequest) (resp providers.ReadResourceResponse) {
|
||||||
|
resp.NewState = cty.NullVal(req.PriorState.Type())
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
addr := mustResourceInstanceAddr("test_object.a")
|
||||||
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
|
s.SetResourceInstanceCurrent(addr, &states.ResourceInstanceObjectSrc{
|
||||||
|
AttrsJSON: []byte(`{"test_string":"foo"}`),
|
||||||
|
Status: states.ObjectTainted,
|
||||||
|
}, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`))
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
State: state,
|
||||||
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, diags := ctx.Plan()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range plan.Changes.Resources {
|
||||||
|
if c.Action != plans.Create {
|
||||||
|
t.Fatalf("expected Create action for missing %s, got %s", c.Addr, c.Action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, diags = ctx.Apply()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.Err())
|
||||||
|
}
|
||||||
|
}
|
|
@ -6732,3 +6732,8 @@ output "planned" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// NOTE: Due to the size of this file, new tests should be added to
|
||||||
|
// context_plan2_test.go.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue