2020-02-11 19:17:37 +01:00
|
|
|
package configs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestNewModule_provider_fqns exercises module.gatherProviderLocalNames()
|
|
|
|
func TestNewModule_provider_local_name(t *testing.T) {
|
|
|
|
mod, diags := testModuleFromDir("testdata/providers-explicit-fqn")
|
|
|
|
if diags.HasErrors() {
|
|
|
|
t.Fatal(diags.Error())
|
|
|
|
}
|
|
|
|
|
2020-03-10 19:43:57 +01:00
|
|
|
p := addrs.NewProvider(addrs.DefaultRegistryHost, "foo", "test")
|
2020-02-11 19:17:37 +01:00
|
|
|
if name, exists := mod.ProviderLocalNames[p]; !exists {
|
|
|
|
t.Fatal("provider FQN foo/test not found")
|
|
|
|
} else {
|
2020-02-15 03:10:03 +01:00
|
|
|
if name != "foo-test" {
|
|
|
|
t.Fatalf("provider localname mismatch: got %s, want foo-test", name)
|
2020-02-11 19:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure the reverse lookup (fqn to local name) works as well
|
|
|
|
localName := mod.LocalNameForProvider(p)
|
2020-02-15 03:10:03 +01:00
|
|
|
if localName != "foo-test" {
|
2020-02-11 19:17:37 +01:00
|
|
|
t.Fatal("provider local name not found")
|
|
|
|
}
|
|
|
|
}
|