From c86ac850a909f347d250a3902db051c09a91c36b Mon Sep 17 00:00:00 2001 From: Samsondeen Dare Date: Fri, 17 Jan 2025 12:58:22 +0100 Subject: [PATCH] move MainStateIdentifier to moduletest --- internal/backend/local/test.go | 13 +++++-------- internal/moduletest/run.go | 6 +++++- internal/terraformtest/transform_test_run.go | 1 - 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/backend/local/test.go b/internal/backend/local/test.go index 516aebc4ed10..91063dee5bdc 100644 --- a/internal/backend/local/test.go +++ b/internal/backend/local/test.go @@ -35,10 +35,6 @@ import ( "github.com/hashicorp/terraform/internal/tfdiags" ) -const ( - MainStateIdentifier = "" -) - type TestSuiteRunner struct { Config *configs.Config @@ -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(), }, @@ -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. @@ -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 diff --git a/internal/moduletest/run.go b/internal/moduletest/run.go index 5db629a8c43c..b481d14b7744 100644 --- a/internal/moduletest/run.go +++ b/internal/moduletest/run.go @@ -19,6 +19,10 @@ import ( "github.com/hashicorp/terraform/internal/tfdiags" ) +const ( + MainStateIdentifier = "" +) + type Run struct { Config *configs.TestRun ModuleConfig *configs.Config @@ -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 diff --git a/internal/terraformtest/transform_test_run.go b/internal/terraformtest/transform_test_run.go index c3b70d671dbb..487d70577d98 100644 --- a/internal/terraformtest/transform_test_run.go +++ b/internal/terraformtest/transform_test_run.go @@ -116,7 +116,6 @@ func (t *TestRunTransformer) connectDependencies(g *terraform.Graph, nodes []*No }) } } - } } return diags