Cleanup ContextPlugins after function changes (#1550)

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh 2024-04-25 07:19:15 -04:00 committed by GitHub
parent c59d95ba0d
commit c90ea9024d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 16 additions and 29 deletions

View File

@ -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")

View File

@ -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 {

View File

@ -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
}

View File

@ -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,

View File

@ -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"),

View File

@ -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"),

View File

@ -50,5 +50,5 @@ func schemaOnlyProvidersForTesting(schemas map[addrs.Provider]providers.Provider
}
}
return newContextPluginsForTest(factories, t)
return newContextPlugins(factories, nil)
}