Skip to content

Commit

Permalink
backport of commit 57ef86b
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcervante committed Dec 14, 2022
1 parent 765b174 commit ca3036e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/initwd/module_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,54 @@ func TestModuleInstaller_explicitPackageBoundary(t *testing.T) {
}
}

func TestModuleInstaller_ExactMatchPrerelease(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("this test accesses registry.terraform.io and github.com; set TF_ACC=1 to run it")
}

fixtureDir := filepath.Clean("testdata/prerelease-version-constraint-match")
dir, done := tempChdir(t, fixtureDir)
defer done()

hooks := &testInstallHooks{}

modulesDir := filepath.Join(dir, ".terraform/modules")
inst := NewModuleInstaller(modulesDir, registry.NewClient(nil, nil))
cfg, diags := inst.InstallModules(context.Background(), ".", false, hooks)

if diags.HasErrors() {
t.Fatalf("found unexpected errors: %s", diags.Err())
}

if !cfg.Children["acctest_exact"].Version.Equal(version.Must(version.NewVersion("v0.0.3-alpha.1"))) {
t.Fatalf("expected version %s but found version %s", "v0.0.3-alpha.1", cfg.Version.String())
}
}

func TestModuleInstaller_PartialMatchPrerelease(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("this test accesses registry.terraform.io and github.com; set TF_ACC=1 to run it")
}

fixtureDir := filepath.Clean("testdata/prerelease-version-constraint")
dir, done := tempChdir(t, fixtureDir)
defer done()

hooks := &testInstallHooks{}

modulesDir := filepath.Join(dir, ".terraform/modules")
inst := NewModuleInstaller(modulesDir, registry.NewClient(nil, nil))
cfg, diags := inst.InstallModules(context.Background(), ".", false, hooks)

if diags.HasErrors() {
t.Fatalf("found unexpected errors: %s", diags.Err())
}

if !cfg.Children["acctest_partial"].Version.Equal(version.Must(version.NewVersion("v0.0.2"))) {
t.Fatalf("expected version %s but found version %s", "v0.0.2", cfg.Version.String())
}
}

func TestModuleInstaller_invalid_version_constraint_error(t *testing.T) {
fixtureDir := filepath.Clean("testdata/invalid-version-constraint")
dir, done := tempChdir(t, fixtureDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# We expect this test to download the requested version because it is an exact
# match for a prerelease version.

module "acctest_exact" {
source = "hashicorp/module-installer-acctest/aws"
version = "=0.0.3-alpha.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# We expect this test to download the version 0.0.2, the one before the
# specified version even with the equality because the specified version is a
# prerelease.

module "acctest_partial" {
source = "hashicorp/module-installer-acctest/aws"
version = "<=0.0.3-alpha.1"
}

0 comments on commit ca3036e

Please sign in to comment.