pull/38449/head
UKEME BASSEY 3 weeks ago
parent c857888605
commit a3ce749dd5

@ -3273,6 +3273,9 @@ main.tftest.hcl... in progress
run "test_four"... pass
run "test_five"... pass
main.tftest.hcl... tearing down
Terraform left the following resources in state after executing
main.tftest.hcl/test_three because the skip_cleanup attribute was set:
- test_resource.resource
main.tftest.hcl... pass
Success! 5 passed, 0 failed.
@ -3543,6 +3546,7 @@ func TestTest_SkipCleanup_JSON(t *testing.T) {
`{"@level":"info","@message":" \"test_five\"... pass","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test_five","test_run":{"path":"main.tftest.hcl","progress":"complete","run":"test_five","status":"pass"},"type":"test_run"}`,
`{"@level":"info","@message":"main.tftest.hcl... tearing down","@module":"terraform.ui","@testfile":"main.tftest.hcl","test_file":{"path":"main.tftest.hcl","progress":"teardown"},"type":"test_file"}`,
`{"@level":"info","@message":" \"test_three\"... tearing down","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test_three","test_run":{"path":"main.tftest.hcl","progress":"teardown","run":"test_three"},"type":"test_run"}`,
`{"@level":"info","@message":"Terraform left some resources in state after executing main.tftest.hcl/test_three because the skip_cleanup attribute was set.","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test_three","test_cleanup_skipped":{"resources":[{"instance":"test_resource.resource"}]},"type":"test_cleanup_skipped"}`,
`{"@level":"info","@message":"main.tftest.hcl... pass","@module":"terraform.ui","@testfile":"main.tftest.hcl","test_file":{"path":"main.tftest.hcl","progress":"complete","status":"pass"},"type":"test_file"}`,
`{"@level":"info","@message":"Success! 5 passed, 0 failed.","@module":"terraform.ui","test_summary":{"errored":0,"failed":0,"passed":5,"skipped":0,"status":"pass"},"type":"test_summary"}`,
}

@ -831,6 +831,30 @@ main.tftest.hcl/run_block.
Error: first error
this time it is very bad
`,
},
"state_with_skip_cleanup": {
run: &moduletest.Run{Name: "run_block", Config: &configs.TestRun{SkipCleanup: true}},
file: &moduletest.File{Name: "main.tftest.hcl"},
state: states.BuildState(func(state *states.SyncState) {
state.SetResourceInstanceCurrent(
addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test",
Name: "foo",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
&states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
},
addrs.AbsProviderConfig{
Module: addrs.RootModule,
Provider: addrs.NewDefaultProvider("test"),
})
}),
stdout: `
Terraform left the following resources in state after executing
main.tftest.hcl/run_block because the skip_cleanup attribute was set:
- test.foo
`,
},
"state_only_warnings": {
@ -1982,6 +2006,42 @@ func TestTestJSON_DestroySummary(t *testing.T) {
},
},
},
"state_from_run_skip_cleanup": {
file: &moduletest.File{Name: "main.tftest.hcl"},
run: &moduletest.Run{Name: "run_block", Config: &configs.TestRun{SkipCleanup: true}},
state: states.BuildState(func(state *states.SyncState) {
state.SetResourceInstanceCurrent(
addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "test",
Name: "foo",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
&states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
},
addrs.AbsProviderConfig{
Module: addrs.RootModule,
Provider: addrs.NewDefaultProvider("test"),
})
}),
want: []map[string]interface{}{
{
"@level": "info",
"@message": "Terraform left some resources in state after executing main.tftest.hcl/run_block because the skip_cleanup attribute was set.",
"@module": "terraform.ui",
"@testfile": "main.tftest.hcl",
"@testrun": "run_block",
"test_cleanup_skipped": map[string]interface{}{
"resources": []interface{}{
map[string]interface{}{
"instance": "test.foo",
},
},
},
"type": "test_cleanup_skipped",
},
},
},
"state_only_warnings": {
diags: tfdiags.Diagnostics{
tfdiags.Sourceless(tfdiags.Warning, "first warning", "something not very bad happened"),

Loading…
Cancel
Save