fix tests after moving incorrect references

The destroy graph builder test requires state in order to be correct,
which it didn't have. The other tests hits the edge case where a planned
destroy cannot remove outputs, because the apply phase does not know it
was created from a destroy.
This commit is contained in:
James Bardin 2020-07-16 09:09:18 -04:00
parent ebe31acc48
commit ca8338e343
2 changed files with 24 additions and 4 deletions

View File

@ -6033,10 +6033,8 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) {
} }
//Test that things were destroyed //Test that things were destroyed
actual := strings.TrimSpace(state.String()) if state.HasResources() {
expected := strings.TrimSpace(`<no state>`) t.Fatal("expected empty state, got:", state)
if actual != expected {
t.Fatalf("expected:\n\n%s\n\nactual:\n\n%s", expected, actual)
} }
} }

View File

@ -321,11 +321,33 @@ func TestApplyGraphBuilder_destroyCount(t *testing.T) {
}, },
} }
state := states.NewState()
root := state.RootModule()
addrA := mustResourceInstanceAddr("test_object.A[1]")
root.SetResourceInstanceCurrent(
addrA.Resource,
&states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{"id":"B"}`),
},
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
)
root.SetResourceInstanceCurrent(
mustResourceInstanceAddr("test_object.B").Resource,
&states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{"id":"B"}`),
Dependencies: []addrs.ConfigResource{addrA.ContainingResource().Config()},
},
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
)
b := &ApplyGraphBuilder{ b := &ApplyGraphBuilder{
Config: testModule(t, "graph-builder-apply-count"), Config: testModule(t, "graph-builder-apply-count"),
Changes: changes, Changes: changes,
Components: simpleMockComponentFactory(), Components: simpleMockComponentFactory(),
Schemas: simpleTestSchemas(), Schemas: simpleTestSchemas(),
State: state,
} }
g, err := b.Build(addrs.RootModuleInstance) g, err := b.Build(addrs.RootModuleInstance)