adds tests for module prerelease version constraints with a v prefix

Signed-off-by: AYM1607 <u.g.a.mariano@gmail.com>
This commit is contained in:
AYM1607 2024-10-31 02:01:07 +00:00 committed by Martin Atkins
parent 5264ccee99
commit 6a5c1a2f42
5 changed files with 60 additions and 42 deletions

View File

@ -235,57 +235,61 @@ func TestModuleInstaller_explicitPackageBoundary(t *testing.T) {
}
}
func TestModuleInstaller_ExactMatchPrerelease(t *testing.T) {
func TestModuleInstaller_Prerelease(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("this test accesses registry.opentofu.org 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")
loader, close := configload.NewLoaderForTests(t)
defer close()
inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(nil, nil))
cfg, diags := inst.InstallModules(context.Background(), ".", "tests", false, false, hooks, configs.RootModuleCallForTesting())
if diags.HasErrors() {
t.Fatalf("found unexpected errors: %s", diags.Err())
testCases := []struct {
name string
modulePath string
expectedVersion string
}{
{
name: "exact match",
modulePath: "testdata/prerelease-version-constraint-match",
expectedVersion: "v0.0.3-alpha.1",
},
{
name: "exact match v prefix",
modulePath: "testdata/prerelease-version-constraint-match-prefix",
expectedVersion: "v0.0.3-alpha.1",
},
{
name: "exact match v prefix eq selector",
modulePath: "testdata/prerelease-version-constraint-match-prefix-eq",
expectedVersion: "v0.0.3-alpha.1",
},
{
name: "partial match",
modulePath: "testdata/prerelease-version-constraint",
expectedVersion: "v0.0.2",
},
}
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())
}
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fixtureDir := filepath.Clean(tc.modulePath)
dir, done := tempChdir(t, fixtureDir)
defer done()
func TestModuleInstaller_PartialMatchPrerelease(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("this test accesses registry.opentofu.org and github.com; set TF_ACC=1 to run it")
}
hooks := &testInstallHooks{}
fixtureDir := filepath.Clean("testdata/prerelease-version-constraint")
dir, done := tempChdir(t, fixtureDir)
defer done()
modulesDir := filepath.Join(dir, ".terraform/modules")
hooks := &testInstallHooks{}
loader, close := configload.NewLoaderForTests(t)
defer close()
inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(nil, nil))
cfg, diags := inst.InstallModules(context.Background(), ".", "tests", false, false, hooks, configs.RootModuleCallForTesting())
modulesDir := filepath.Join(dir, ".terraform/modules")
if diags.HasErrors() {
t.Fatalf("found unexpected errors: %s", diags.Err())
}
loader, close := configload.NewLoaderForTests(t)
defer close()
inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(nil, nil))
cfg, diags := inst.InstallModules(context.Background(), ".", "tests", false, false, hooks, configs.RootModuleCallForTesting())
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())
if !cfg.Children["acctest"].Version.Equal(version.Must(version.NewVersion(tc.expectedVersion))) {
t.Fatalf("expected version %s but found version %s", tc.expectedVersion, cfg.Version.String())
}
})
}
}

View File

@ -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" {
source = "hashicorp/module-installer-acctest/aws"
version = "=v0.0.3-alpha.1"
}

View File

@ -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" {
source = "hashicorp/module-installer-acctest/aws"
version = "v0.0.3-alpha.1"
}

View File

@ -1,7 +1,7 @@
# We expect this test to download the requested version because it is an exact
# match for a prerelease version.
module "acctest_exact" {
module "acctest" {
source = "hashicorp/module-installer-acctest/aws"
version = "=0.0.3-alpha.1"
}

View File

@ -2,7 +2,7 @@
# specified version even with the equality because the specified version is a
# prerelease.
module "acctest_partial" {
module "acctest" {
source = "hashicorp/module-installer-acctest/aws"
version = "<=0.0.3-alpha.1"
}