Skip to content

Commit

Permalink
skip errored before any execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Feb 5, 2025
1 parent 9bce19f commit 9555a29
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
39 changes: 19 additions & 20 deletions internal/backend/local/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics

switch v := v.(type) {
case *graph.NodeTestRun:
file := v.File()
run := v.Run()
if file.GetStatus() == moduletest.Error {
// If the overall test file has errored, we don't keep trying to
// execute tests. Instead, we mark all remaining run blocks as
// skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
return
}
if runner.Suite.Stopped {
// Then the test was requested to be stopped, so we just mark each
// following test as skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
return
}

// TODO: The execution of a NodeTestRun is currently split between
// its Execute method and the continuation of the walk callback.
// Eventually, we should move all the logic related to a test run into
Expand All @@ -356,7 +374,7 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
if diags.HasErrors() {
return diags
}
// continue
// continue the execution of the test run.
case graph.GraphNodeExecutable:
diags = v.Execute(runner.EvalContext)
return diags
Expand All @@ -371,25 +389,6 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
file := runNode.File()
run := runNode.Run()

if runner.Suite.Stopped {
// Then the test was requested to be stopped, so we just mark each
// following test as skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
return
}
file.Lock()
if file.Status == moduletest.Error {
// If the overall test file has errored, we don't keep trying to
// execute tests. Instead, we mark all remaining run blocks as
// skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
file.Unlock()
return
}
file.Unlock()

key := run.GetStateKey()
if run.Config.ConfigUnderTest != nil {
if key == moduletest.MainStateIdentifier {
Expand Down
6 changes: 6 additions & 0 deletions internal/moduletest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func (f *File) UpdateStatus(status Status) {
defer f.Unlock()
f.Status = f.Status.Merge(status)
}

func (f *File) GetStatus() Status {
f.Lock()
defer f.Unlock()
return f.Status
}
2 changes: 2 additions & 0 deletions internal/moduletest/graph/node_test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/hashicorp/terraform/internal/tfdiags"
)

var _ GraphNodeExecutable = (*NodeTestRun)(nil)

type NodeTestRun struct {
file *moduletest.File
run *moduletest.Run
Expand Down

0 comments on commit 9555a29

Please sign in to comment.