mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
e89b5390ca
As we add support for versioned providers, it's getting more complex to track the dependencies of each module and of the configuration as a whole, so this new package is intended to give us some room to model that nicely as a building block for the various aspects of dependency management. This package is not responsible for *building* the dependency data structure, since that requires knowledge of core Terraform and that would create cyclic package dependencies. A later change will add some logic in Terraform to create a Module tree based on the combination of a given configuration and state, returning an instance of this package's Module type. The Module.PluginRequirements method flattens the provider-oriented requirements into a set of plugin-oriented requirements (flattening any provider aliases) giving us what we need to work with the plugin/discovery package to find matching installed plugins. Other later uses of this package will include selecting plugin archives to auto-install from releases.hashicorp.com as part of "terraform init", where the module-oriented level of abstraction here should be useful for giving users good, specific feedback when constraints cannot be met. A "reason" is tracked for each provider dependency with the intent that this would later drive a UI for users to see and understand why a given dependency is present, to aid in debugging sticky issues with dependency resolution.
37 lines
666 B
Go
37 lines
666 B
Go
package moduledeps
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestProviderInstance(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
WantType string
|
|
WantAlias string
|
|
}{
|
|
{
|
|
Name: "aws",
|
|
WantType: "aws",
|
|
WantAlias: "",
|
|
},
|
|
{
|
|
Name: "aws.foo",
|
|
WantType: "aws",
|
|
WantAlias: "foo",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
inst := ProviderInstance(test.Name)
|
|
if got, want := inst.Type(), test.WantType; got != want {
|
|
t.Errorf("got type %q; want %q", got, want)
|
|
}
|
|
if got, want := inst.Alias(), test.WantAlias; got != want {
|
|
t.Errorf("got alias %q; want %q", got, want)
|
|
}
|
|
})
|
|
}
|
|
}
|