Skip to content

Commit

Permalink
move MainStateIdentifier to moduletest
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Jan 17, 2025
1 parent 861afba commit c86ac85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
13 changes: 5 additions & 8 deletions internal/backend/local/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ import (
"github.com/hashicorp/terraform/internal/tfdiags"
)

const (
MainStateIdentifier = ""
)

type TestSuiteRunner struct {
Config *configs.Config

Expand Down Expand Up @@ -157,7 +153,7 @@ func (runner *TestSuiteRunner) Test() (moduletest.Status, tfdiags.Diagnostics) {
fileRunner := &TestFileRunner{
Suite: runner,
RelevantStates: map[string]*TestFileState{
MainStateIdentifier: {
moduletest.MainStateIdentifier: {
Run: nil,
State: states.NewState(),
},
Expand Down Expand Up @@ -424,7 +420,7 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics
key := run.GetStateKey()
config := run.ModuleConfig
if run.Config.ConfigUnderTest != nil {
if key == MainStateIdentifier {
if key == moduletest.MainStateIdentifier {
// This is bad. It means somehow the module we're loading has
// the same key as main state and we're about to corrupt things.

Expand Down Expand Up @@ -927,9 +923,10 @@ func (runner *TestFileRunner) wait(ctx *terraform.Context, runningCtx context.Co
log.Printf("[DEBUG] TestFileRunner: test execution cancelled during %s", identifier)

states := make(map[*moduletest.Run]*states.State)
states[nil] = runner.RelevantStates[MainStateIdentifier].State
mainKey := moduletest.MainStateIdentifier
states[nil] = runner.RelevantStates[mainKey].State
for key, module := range runner.RelevantStates {
if key == MainStateIdentifier {
if key == mainKey {
continue
}
states[module.Run] = module.State
Expand Down
6 changes: 5 additions & 1 deletion internal/moduletest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/hashicorp/terraform/internal/tfdiags"
)

const (
MainStateIdentifier = ""
)

type Run struct {
Config *configs.TestRun
ModuleConfig *configs.Config
Expand Down Expand Up @@ -163,7 +167,7 @@ func (run *Run) GetStateKey() string {
return run.Config.Module.Source.String()
}

return ""
return MainStateIdentifier
}

// ExplainExpectedFailures is similar to ValidateExpectedFailures except it
Expand Down
1 change: 0 additions & 1 deletion internal/terraformtest/transform_test_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func (t *TestRunTransformer) connectDependencies(g *terraform.Graph, nodes []*No
})
}
}

}
}
return diags
Expand Down

0 comments on commit c86ac85

Please sign in to comment.