addrs: Fix LegacyString for builtin provider addrs
Builtin provider addrs (i.e. "terraform.io/builtin/terraform") should be able to convert to legacy string form (i.e. "terraform"). This ensures that we can safely round-trip through ParseLegacyAbsProviderConfig, which can return either a legacy or a builtin provider addr.
This commit is contained in:
parent
95eca06782
commit
d53a4ac588
|
@ -156,8 +156,8 @@ func (pt Provider) LegacyString() string {
|
||||||
if pt.IsZero() {
|
if pt.IsZero() {
|
||||||
panic("called LegacyString on zero-value addrs.Provider")
|
panic("called LegacyString on zero-value addrs.Provider")
|
||||||
}
|
}
|
||||||
if pt.Namespace != LegacyProviderNamespace {
|
if pt.Namespace != LegacyProviderNamespace && pt.Namespace != BuiltInProviderNamespace {
|
||||||
panic(pt.String() + " is not a legacy addrs.Provider")
|
panic(pt.String() + " cannot be represented as a legacy string")
|
||||||
}
|
}
|
||||||
return pt.Type
|
return pt.Type
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,37 @@ func TestProviderString(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProviderLegacyString(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
Input Provider
|
||||||
|
Want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Provider{
|
||||||
|
Type: "test",
|
||||||
|
Hostname: DefaultRegistryHost,
|
||||||
|
Namespace: LegacyProviderNamespace,
|
||||||
|
},
|
||||||
|
"test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Provider{
|
||||||
|
Type: "terraform",
|
||||||
|
Hostname: BuiltInProviderHost,
|
||||||
|
Namespace: BuiltInProviderNamespace,
|
||||||
|
},
|
||||||
|
"terraform",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
got := test.Input.LegacyString()
|
||||||
|
if got != test.Want {
|
||||||
|
t.Errorf("wrong result for %s\ngot: %s\nwant: %s", test.Input.String(), got, test.Want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestProviderDisplay(t *testing.T) {
|
func TestProviderDisplay(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Input Provider
|
Input Provider
|
||||||
|
|
Loading…
Reference in New Issue