mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Fix flaky test in views package (#33560)
This commit is contained in:
parent
c91f91cc9e
commit
ad26644578
@ -243,31 +243,33 @@ func (t *TestHuman) FatalInterrupt() {
|
|||||||
func (t *TestHuman) FatalInterruptSummary(run *moduletest.Run, file *moduletest.File, existingStates map[*moduletest.Run]*states.State, created []*plans.ResourceInstanceChangeSrc) {
|
func (t *TestHuman) FatalInterruptSummary(run *moduletest.Run, file *moduletest.File, existingStates map[*moduletest.Run]*states.State, created []*plans.ResourceInstanceChangeSrc) {
|
||||||
t.view.streams.Eprint(format.WordWrap(fmt.Sprintf("\nTerraform was interrupted while executing %s, and may not have performed the expected cleanup operations.\n", file.Name), t.view.errorColumns()))
|
t.view.streams.Eprint(format.WordWrap(fmt.Sprintf("\nTerraform was interrupted while executing %s, and may not have performed the expected cleanup operations.\n", file.Name), t.view.errorColumns()))
|
||||||
|
|
||||||
for run, state := range existingStates {
|
// Print out the main state first, this is the state that isn't associated
|
||||||
if state.Empty() {
|
// with a run block.
|
||||||
// Then it's fine, don't worry about it.
|
if state, exists := existingStates[nil]; exists && !state.Empty() {
|
||||||
|
t.view.streams.Eprint(format.WordWrap("\nTerraform has already created the following resources from the module under test:\n", t.view.errorColumns()))
|
||||||
|
for _, resource := range state.AllResourceInstanceObjectAddrs() {
|
||||||
|
if resource.DeposedKey != states.NotDeposed {
|
||||||
|
t.view.streams.Eprintf(" - %s (%s)\n", resource.Instance, resource.DeposedKey)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t.view.streams.Eprintf(" - %s\n", resource.Instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then print out the other states in order.
|
||||||
|
for _, run := range file.Runs {
|
||||||
|
state, exists := existingStates[run]
|
||||||
|
if !exists || state.Empty() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if run == nil {
|
t.view.streams.Eprint(format.WordWrap(fmt.Sprintf("\nTerraform has already created the following resources for %q from %q:\n", run.Name, run.Config.Module.Source), t.view.errorColumns()))
|
||||||
// Then this is just the main state for the whole file.
|
for _, resource := range state.AllResourceInstanceObjectAddrs() {
|
||||||
t.view.streams.Eprint(format.WordWrap("\nTerraform has already created the following resources from the module under test:\n", t.view.errorColumns()))
|
if resource.DeposedKey != states.NotDeposed {
|
||||||
for _, resource := range state.AllResourceInstanceObjectAddrs() {
|
t.view.streams.Eprintf(" - %s (%s)\n", resource.Instance, resource.DeposedKey)
|
||||||
if resource.DeposedKey != states.NotDeposed {
|
continue
|
||||||
t.view.streams.Eprintf(" - %s (%s)\n", resource.Instance, resource.DeposedKey)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t.view.streams.Eprintf(" - %s\n", resource.Instance)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.view.streams.Eprint(format.WordWrap(fmt.Sprintf("\nTerraform has already created the following resources for %q from %q:\n", run.Name, run.Config.Module.Source), t.view.errorColumns()))
|
|
||||||
for _, resource := range state.AllResourceInstanceObjectAddrs() {
|
|
||||||
if resource.DeposedKey != states.NotDeposed {
|
|
||||||
t.view.streams.Eprintf(" - %s (%s)\n", resource.Instance, resource.DeposedKey)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
t.view.streams.Eprintf(" - %s\n", resource.Instance)
|
|
||||||
}
|
}
|
||||||
|
t.view.streams.Eprintf(" - %s\n", resource.Instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1200,16 +1200,16 @@ Terraform has already created the following resources for "setup_block" from
|
|||||||
Terraform was interrupted while executing main.tftest.hcl, and may not have
|
Terraform was interrupted while executing main.tftest.hcl, and may not have
|
||||||
performed the expected cleanup operations.
|
performed the expected cleanup operations.
|
||||||
|
|
||||||
Terraform has already created the following resources for "setup_block" from
|
|
||||||
"../setup":
|
|
||||||
- test_instance.setup_one
|
|
||||||
- test_instance.setup_two
|
|
||||||
|
|
||||||
Terraform has already created the following resources from the module under
|
Terraform has already created the following resources from the module under
|
||||||
test:
|
test:
|
||||||
- test_instance.one
|
- test_instance.one
|
||||||
- test_instance.two
|
- test_instance.two
|
||||||
|
|
||||||
|
Terraform has already created the following resources for "setup_block" from
|
||||||
|
"../setup":
|
||||||
|
- test_instance.setup_one
|
||||||
|
- test_instance.setup_two
|
||||||
|
|
||||||
Terraform was in the process of creating the following resources for
|
Terraform was in the process of creating the following resources for
|
||||||
"run_block" from the module under test, and they may not have been destroyed:
|
"run_block" from the module under test, and they may not have been destroyed:
|
||||||
- test_instance.new_one
|
- test_instance.new_one
|
||||||
@ -1222,7 +1222,18 @@ Terraform was in the process of creating the following resources for
|
|||||||
streams, done := terminal.StreamsForTesting(t)
|
streams, done := terminal.StreamsForTesting(t)
|
||||||
view := NewTest(arguments.ViewHuman, NewView(streams))
|
view := NewTest(arguments.ViewHuman, NewView(streams))
|
||||||
|
|
||||||
file := &moduletest.File{Name: "main.tftest.hcl"}
|
file := &moduletest.File{
|
||||||
|
Name: "main.tftest.hcl",
|
||||||
|
Runs: func() []*moduletest.Run {
|
||||||
|
var runs []*moduletest.Run
|
||||||
|
for run := range tc.states {
|
||||||
|
if run != nil {
|
||||||
|
runs = append(runs, run)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return runs
|
||||||
|
}(),
|
||||||
|
}
|
||||||
|
|
||||||
view.FatalInterruptSummary(tc.run, file, tc.states, tc.created)
|
view.FatalInterruptSummary(tc.run, file, tc.states, tc.created)
|
||||||
actual, expected := done(t).Stderr(), tc.want
|
actual, expected := done(t).Stderr(), tc.want
|
||||||
|
Loading…
Reference in New Issue
Block a user