Skip to content

Commit 74e4d8d

Browse files
committed
skip errored before any execution
1 parent 9bce19f commit 74e4d8d

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

internal/backend/local/test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
347347

348348
switch v := v.(type) {
349349
case *graph.NodeTestRun:
350+
file := v.File()
351+
run := v.Run()
352+
if file.GetStatus() == moduletest.Error {
353+
// If the overall test file has errored, we don't keep trying to
354+
// execute tests. Instead, we mark all remaining run blocks as
355+
// skipped, print the status, and move on.
356+
run.Status = moduletest.Skip
357+
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
358+
return
359+
}
360+
350361
// TODO: The execution of a NodeTestRun is currently split between
351362
// its Execute method and the continuation of the walk callback.
352363
// Eventually, we should move all the logic related to a test run into
@@ -356,7 +367,7 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
356367
if diags.HasErrors() {
357368
return diags
358369
}
359-
// continue
370+
// continue the execution of the test run.
360371
case graph.GraphNodeExecutable:
361372
diags = v.Execute(runner.EvalContext)
362373
return diags
@@ -378,17 +389,6 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
378389
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
379390
return
380391
}
381-
file.Lock()
382-
if file.Status == moduletest.Error {
383-
// If the overall test file has errored, we don't keep trying to
384-
// execute tests. Instead, we mark all remaining run blocks as
385-
// skipped, print the status, and move on.
386-
run.Status = moduletest.Skip
387-
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
388-
file.Unlock()
389-
return
390-
}
391-
file.Unlock()
392392

393393
key := run.GetStateKey()
394394
if run.Config.ConfigUnderTest != nil {

internal/moduletest/file.go

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ func (f *File) UpdateStatus(status Status) {
3737
defer f.Unlock()
3838
f.Status = f.Status.Merge(status)
3939
}
40+
41+
func (f *File) GetStatus() Status {
42+
f.Lock()
43+
defer f.Unlock()
44+
return f.Status
45+
}

internal/moduletest/graph/node_test_run.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/hashicorp/terraform/internal/tfdiags"
1111
)
1212

13+
var _ GraphNodeExecutable = (*NodeTestRun)(nil)
14+
1315
type NodeTestRun struct {
1416
file *moduletest.File
1517
run *moduletest.Run

0 commit comments

Comments
 (0)