From f09ae6f8620d0d91a56433a91da5b1ab1c805328 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Thu, 16 Apr 2020 15:54:33 -0400 Subject: [PATCH] provider source tests: added test suite to exercise hyphenated providers (#24685) --- addrs/provider_test.go | 10 +++++++++- command/init_test.go | 19 +++++++++++++++++-- .../testdata/init-required-providers/main.tf | 3 +++ .../filesystem_mirror_source_test.go | 15 +++++++++++++++ .../terraform-provider-random-beta | 1 + internal/providercache/dir_test.go | 11 +++++++++++ .../terraform-provider-random-beta | 1 + 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 internal/getproviders/testdata/filesystem-mirror/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta create mode 100644 internal/providercache/testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta diff --git a/addrs/provider_test.go b/addrs/provider_test.go index 3abc96e11..e0c996c0e 100644 --- a/addrs/provider_test.go +++ b/addrs/provider_test.go @@ -18,7 +18,15 @@ func TestProviderString(t *testing.T) { Hostname: DefaultRegistryHost, Namespace: "hashicorp", }, - DefaultRegistryHost.ForDisplay() + "/hashicorp/test", + NewDefaultProvider("test").String(), + }, + { + Provider{ + Type: "test-beta", + Hostname: DefaultRegistryHost, + Namespace: "hashicorp", + }, + NewDefaultProvider("test-beta").String(), }, { Provider{ diff --git a/command/init_test.go b/command/init_test.go index 006fb902e..df81157da 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -858,8 +858,9 @@ func TestInit_providerSource(t *testing.T) { defer testChdir(t, td)() providerSource, close := newMockProviderSource(t, map[string][]string{ - "test": []string{"1.2.3", "1.2.4"}, - "source": []string{"1.2.2", "1.2.3", "1.2.1"}, + "test": []string{"1.2.3", "1.2.4"}, + "test-beta": []string{"1.2.4"}, + "source": []string{"1.2.2", "1.2.3", "1.2.1"}, }) defer close() @@ -894,6 +895,14 @@ func TestInit_providerSource(t *testing.T) { ExecutableFile: expectedPackageInstallPath("test", "1.2.3", true), }, }, + addrs.NewDefaultProvider("test-beta"): { + { + Provider: addrs.NewDefaultProvider("test-beta"), + Version: getproviders.MustParseVersion("1.2.4"), + PackageDir: expectedPackageInstallPath("test-beta", "1.2.4", false), + ExecutableFile: expectedPackageInstallPath("test-beta", "1.2.4", true), + }, + }, addrs.NewDefaultProvider("source"): { { Provider: addrs.NewDefaultProvider("source"), @@ -913,6 +922,12 @@ func TestInit_providerSource(t *testing.T) { t.Fatalf("failed to get selected packages from installer: %s", err) } wantSelected := map[addrs.Provider]*providercache.CachedProvider{ + addrs.NewDefaultProvider("test-beta"): { + Provider: addrs.NewDefaultProvider("test-beta"), + Version: getproviders.MustParseVersion("1.2.4"), + PackageDir: expectedPackageInstallPath("test-beta", "1.2.4", false), + ExecutableFile: expectedPackageInstallPath("test-beta", "1.2.4", true), + }, addrs.NewDefaultProvider("test"): { Provider: addrs.NewDefaultProvider("test"), Version: getproviders.MustParseVersion("1.2.3"), diff --git a/command/testdata/init-required-providers/main.tf b/command/testdata/init-required-providers/main.tf index d1f51a32c..20dac12b8 100644 --- a/command/testdata/init-required-providers/main.tf +++ b/command/testdata/init-required-providers/main.tf @@ -4,5 +4,8 @@ terraform { source = { version = "1.2.3" } + test-beta = { + version = "1.2.4" + } } } diff --git a/internal/getproviders/filesystem_mirror_source_test.go b/internal/getproviders/filesystem_mirror_source_test.go index 5757bf97d..6d66dd29b 100644 --- a/internal/getproviders/filesystem_mirror_source_test.go +++ b/internal/getproviders/filesystem_mirror_source_test.go @@ -48,6 +48,15 @@ func TestFilesystemMirrorSourceAllAvailablePackages(t *testing.T) { Location: PackageLocalDir("testdata/filesystem-mirror/registry.terraform.io/hashicorp/null/2.0.0/windows_amd64"), }, }, + randomBetaProvider: { + { + Provider: randomBetaProvider, + Version: versions.MustParseVersion("1.2.0"), + TargetPlatform: Platform{"linux", "amd64"}, + Filename: "terraform-provider-random-beta_1.2.0_linux_amd64.zip", + Location: PackageLocalDir("testdata/filesystem-mirror/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64"), + }, + }, randomProvider: { { Provider: randomProvider, @@ -57,6 +66,7 @@ func TestFilesystemMirrorSourceAllAvailablePackages(t *testing.T) { Location: PackageLocalDir("testdata/filesystem-mirror/registry.terraform.io/hashicorp/random/1.2.0/linux_amd64"), }, }, + happycloudProvider: { { Provider: happycloudProvider, @@ -158,6 +168,11 @@ var randomProvider = addrs.Provider{ Namespace: "hashicorp", Type: "random", } +var randomBetaProvider = addrs.Provider{ + Hostname: svchost.Hostname("registry.terraform.io"), + Namespace: "hashicorp", + Type: "random-beta", +} var happycloudProvider = addrs.Provider{ Hostname: svchost.Hostname("tfe.example.com"), Namespace: "awesomecorp", diff --git a/internal/getproviders/testdata/filesystem-mirror/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta b/internal/getproviders/testdata/filesystem-mirror/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta new file mode 100644 index 000000000..daa9e3509 --- /dev/null +++ b/internal/getproviders/testdata/filesystem-mirror/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta @@ -0,0 +1 @@ +# This is just a placeholder file for discovery testing, not a real provider plugin. diff --git a/internal/providercache/dir_test.go b/internal/providercache/dir_test.go index ee1dbed46..cfc7c54cf 100644 --- a/internal/providercache/dir_test.go +++ b/internal/providercache/dir_test.go @@ -30,6 +30,9 @@ func TestDirReading(t *testing.T) { randomProvider := addrs.NewProvider( addrs.DefaultRegistryHost, "hashicorp", "random", ) + randomBetaProvider := addrs.NewProvider( + addrs.DefaultRegistryHost, "hashicorp", "random-beta", + ) nonExistProvider := addrs.NewProvider( addrs.DefaultRegistryHost, "bloop", "nonexist", ) @@ -160,6 +163,14 @@ func TestDirReading(t *testing.T) { ExecutableFile: "testdata/cachedir/registry.terraform.io/hashicorp/random/1.2.0/linux_amd64/terraform-provider-random", }, }, + randomBetaProvider: { + { + Provider: randomBetaProvider, + Version: versions.MustParseVersion("1.2.0"), + PackageDir: "testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64", + ExecutableFile: "testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta", + }, + }, } if diff := cmp.Diff(want, got); diff != "" { diff --git a/internal/providercache/testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta b/internal/providercache/testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta new file mode 100644 index 000000000..daa9e3509 --- /dev/null +++ b/internal/providercache/testdata/cachedir/registry.terraform.io/hashicorp/random-beta/1.2.0/linux_amd64/terraform-provider-random-beta @@ -0,0 +1 @@ +# This is just a placeholder file for discovery testing, not a real provider plugin.