From c90ea9024d32cf90ba07bdbc0a1f1728dca96d3b Mon Sep 17 00:00:00 2001 From: Christian Mesh Date: Thu, 25 Apr 2024 07:19:15 -0400 Subject: [PATCH] Cleanup ContextPlugins after function changes (#1550) Signed-off-by: Christian Mesh --- internal/tofu/context.go | 5 +---- internal/tofu/context_plugins.go | 4 ++-- internal/tofu/context_plugins_test.go | 10 ---------- internal/tofu/eval_context_builtin_test.go | 4 ++-- internal/tofu/graph_builder_apply_test.go | 4 ++-- internal/tofu/graph_builder_plan_test.go | 16 ++++++++-------- internal/tofu/schemas_test.go | 2 +- 7 files changed, 16 insertions(+), 29 deletions(-) diff --git a/internal/tofu/context.go b/internal/tofu/context.go index a43d4b733e..3f99b9825b 100644 --- a/internal/tofu/context.go +++ b/internal/tofu/context.go @@ -134,10 +134,7 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) { par = 10 } - plugins, err := newContextPlugins(opts.Providers, opts.Provisioners) - if err != nil { - return nil, diags.Append(err) - } + plugins := newContextPlugins(opts.Providers, opts.Provisioners) log.Printf("[TRACE] tofu.NewContext: complete") diff --git a/internal/tofu/context_plugins.go b/internal/tofu/context_plugins.go index 14dd54f6ec..b83f198f8b 100644 --- a/internal/tofu/context_plugins.go +++ b/internal/tofu/context_plugins.go @@ -24,11 +24,11 @@ type contextPlugins struct { provisionerFactories map[string]provisioners.Factory } -func newContextPlugins(providerFactories map[addrs.Provider]providers.Factory, provisionerFactories map[string]provisioners.Factory) (*contextPlugins, error) { +func newContextPlugins(providerFactories map[addrs.Provider]providers.Factory, provisionerFactories map[string]provisioners.Factory) *contextPlugins { return &contextPlugins{ providerFactories: providerFactories, provisionerFactories: provisionerFactories, - }, nil // TODO remove error from this function call! + } } func (cp *contextPlugins) HasProvider(addr addrs.Provider) bool { diff --git a/internal/tofu/context_plugins_test.go b/internal/tofu/context_plugins_test.go index 4fbceb6fe7..234461249b 100644 --- a/internal/tofu/context_plugins_test.go +++ b/internal/tofu/context_plugins_test.go @@ -6,8 +6,6 @@ package tofu import ( - "testing" - "github.com/zclconf/go-cty/cty" "github.com/opentofu/opentofu/internal/addrs" @@ -87,11 +85,3 @@ func simpleTestSchema() *configschema.Block { }, } } - -func newContextPluginsForTest(providerFactories map[addrs.Provider]providers.Factory, t *testing.T) *contextPlugins { - plugins, err := newContextPlugins(providerFactories, nil) - if err != nil { - t.Fatal(err.Error()) - } - return plugins -} diff --git a/internal/tofu/eval_context_builtin_test.go b/internal/tofu/eval_context_builtin_test.go index c8dda08ad2..98a5f7bc90 100644 --- a/internal/tofu/eval_context_builtin_test.go +++ b/internal/tofu/eval_context_builtin_test.go @@ -64,9 +64,9 @@ func TestBuildingEvalContextInitProvider(t *testing.T) { ctx = ctx.WithPath(addrs.RootModuleInstance).(*BuiltinEvalContext) ctx.ProviderLock = &lock ctx.ProviderCache = make(map[string]providers.Interface) - ctx.Plugins = newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + ctx.Plugins = newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("test"): providers.FactoryFixed(testP), - }, t) + }, nil) providerAddrDefault := addrs.AbsProviderConfig{ Module: addrs.RootModule, diff --git a/internal/tofu/graph_builder_apply_test.go b/internal/tofu/graph_builder_apply_test.go index 1bc6818987..72a5394303 100644 --- a/internal/tofu/graph_builder_apply_test.go +++ b/internal/tofu/graph_builder_apply_test.go @@ -732,9 +732,9 @@ func TestApplyGraphBuilder_withChecks(t *testing.T) { }, } - plugins := newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + plugins := newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider), - }, t) + }, nil) b := &ApplyGraphBuilder{ Config: testModule(t, "apply-with-checks"), diff --git a/internal/tofu/graph_builder_plan_test.go b/internal/tofu/graph_builder_plan_test.go index dcd6feae2d..f8e1897fc0 100644 --- a/internal/tofu/graph_builder_plan_test.go +++ b/internal/tofu/graph_builder_plan_test.go @@ -33,10 +33,10 @@ func TestPlanGraphBuilder(t *testing.T) { }, } openstackProvider := mockProviderWithResourceTypeSchema("openstack_floating_ip", simpleTestSchema()) - plugins := newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + plugins := newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider), addrs.NewDefaultProvider("openstack"): providers.FactoryFixed(openstackProvider), - }, t) + }, nil) b := &PlanGraphBuilder{ Config: testModule(t, "graph-builder-plan-basic"), @@ -77,9 +77,9 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) { }, }, }) - plugins := newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + plugins := newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), - }, t) + }, nil) b := &PlanGraphBuilder{ Config: testModule(t, "graph-builder-plan-dynblock"), @@ -133,9 +133,9 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) { }, }, }) - plugins := newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + plugins := newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider), - }, t) + }, nil) b := &PlanGraphBuilder{ Config: testModule(t, "graph-builder-plan-attr-as-blocks"), @@ -198,9 +198,9 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) { func TestPlanGraphBuilder_forEach(t *testing.T) { awsProvider := mockProviderWithResourceTypeSchema("aws_instance", simpleTestSchema()) - plugins := newContextPluginsForTest(map[addrs.Provider]providers.Factory{ + plugins := newContextPlugins(map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider), - }, t) + }, nil) b := &PlanGraphBuilder{ Config: testModule(t, "plan-for-each"), diff --git a/internal/tofu/schemas_test.go b/internal/tofu/schemas_test.go index 5d67f12830..d348e67557 100644 --- a/internal/tofu/schemas_test.go +++ b/internal/tofu/schemas_test.go @@ -50,5 +50,5 @@ func schemaOnlyProvidersForTesting(schemas map[addrs.Provider]providers.Provider } } - return newContextPluginsForTest(factories, t) + return newContextPlugins(factories, nil) }