mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
47a16b0937
a large refactor to addrs.AbsProviderConfig, embedding the addrs.Provider instead of a Type string. I've added and updated tests, added some Legacy functions to support older state formats and shims, and added a normalization step when reading v4 (current) state files (not the added tests under states/statefile/roundtrip which work with both current and legacy-style AbsProviderConfig strings). The remaining 'fixme' and 'todo' comments are mostly going to be addressed in a subsequent PR and involve looking up a given local provider config's FQN. This is fine for now as we are only working with default assumption.
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package plans
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-test/deep"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
func TestProviderAddrs(t *testing.T) {
|
|
|
|
plan := &Plan{
|
|
VariableValues: map[string]DynamicValue{},
|
|
Changes: &Changes{
|
|
Resources: []*ResourceInstanceChangeSrc{
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
|
|
ProviderAddr: addrs.AbsProviderConfig{
|
|
Module: addrs.RootModuleInstance,
|
|
Provider: addrs.NewLegacyProvider("test"),
|
|
},
|
|
},
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "woot",
|
|
}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
|
|
DeposedKey: "foodface",
|
|
ProviderAddr: addrs.AbsProviderConfig{
|
|
Module: addrs.RootModuleInstance,
|
|
Provider: addrs.NewLegacyProvider("test"),
|
|
},
|
|
},
|
|
{
|
|
Addr: addrs.Resource{
|
|
Mode: addrs.ManagedResourceMode,
|
|
Type: "test_thing",
|
|
Name: "what",
|
|
}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
|
|
ProviderAddr: addrs.AbsProviderConfig{
|
|
Module: addrs.RootModuleInstance.Child("foo", addrs.NoKey),
|
|
Provider: addrs.NewLegacyProvider("test"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
got := plan.ProviderAddrs()
|
|
want := []addrs.AbsProviderConfig{
|
|
addrs.AbsProviderConfig{
|
|
Module: addrs.RootModuleInstance.Child("foo", addrs.NoKey),
|
|
Provider: addrs.NewLegacyProvider("test"),
|
|
},
|
|
addrs.AbsProviderConfig{
|
|
Module: addrs.RootModuleInstance,
|
|
Provider: addrs.NewLegacyProvider("test"),
|
|
},
|
|
}
|
|
|
|
for _, problem := range deep.Equal(got, want) {
|
|
t.Error(problem)
|
|
}
|
|
}
|