2020-01-22 01:01:49 +01:00
|
|
|
package getproviders
|
|
|
|
|
|
|
|
import (
|
2020-05-08 17:40:55 +02:00
|
|
|
"strings"
|
2020-01-22 01:01:49 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLookupLegacyProvider(t *testing.T) {
|
|
|
|
source, _, close := testRegistrySource(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
got, err := LookupLegacyProvider(
|
|
|
|
addrs.NewLegacyProvider("legacy"),
|
|
|
|
source,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
want := addrs.Provider{
|
|
|
|
Hostname: defaultRegistryHost,
|
|
|
|
Namespace: "legacycorp",
|
|
|
|
Type: "legacy",
|
|
|
|
}
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, want)
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 17:40:55 +02:00
|
|
|
|
|
|
|
func TestLookupLegacyProvider_invalidResponse(t *testing.T) {
|
|
|
|
source, _, close := testRegistrySource(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
got, err := LookupLegacyProvider(
|
|
|
|
addrs.NewLegacyProvider("invalid"),
|
|
|
|
source,
|
|
|
|
)
|
|
|
|
if !got.IsZero() {
|
|
|
|
t.Errorf("got non-zero addr\ngot: %#v\nwant: %#v", got, nil)
|
|
|
|
}
|
|
|
|
wantErr := "Error parsing provider ID from Registry: Invalid provider source string"
|
|
|
|
if gotErr := err.Error(); !strings.Contains(gotErr, wantErr) {
|
|
|
|
t.Fatalf("unexpected error: got %q, want %q", gotErr, wantErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupLegacyProvider_unexpectedTypeChange(t *testing.T) {
|
|
|
|
source, _, close := testRegistrySource(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
got, err := LookupLegacyProvider(
|
|
|
|
addrs.NewLegacyProvider("changetype"),
|
|
|
|
source,
|
|
|
|
)
|
|
|
|
if !got.IsZero() {
|
|
|
|
t.Errorf("got non-zero addr\ngot: %#v\nwant: %#v", got, nil)
|
|
|
|
}
|
|
|
|
wantErr := `Registry returned provider with type "newtype", expected "changetype"`
|
|
|
|
if gotErr := err.Error(); gotErr != wantErr {
|
|
|
|
t.Fatalf("unexpected error: got %q, want %q", gotErr, wantErr)
|
|
|
|
}
|
|
|
|
}
|