diff --git a/internal/initwd/module_install_test.go b/internal/initwd/module_install_test.go index 0eca62fc3..8828fa75c 100644 --- a/internal/initwd/module_install_test.go +++ b/internal/initwd/module_install_test.go @@ -129,6 +129,42 @@ func TestModuleInstaller_invalid_version_constraint_error(t *testing.T) { } } +func TestModuleInstaller_invalidVersionConstraintGetter(t *testing.T) { + fixtureDir := filepath.Clean("test-fixtures/invalid-version-constraint") + dir, done := tempChdir(t, fixtureDir) + defer done() + + hooks := &testInstallHooks{} + + modulesDir := filepath.Join(dir, ".terraform/modules") + inst := NewModuleInstaller(modulesDir, nil) + _, diags := inst.InstallModules(".", false, hooks) + + if !diags.HasErrors() { + t.Fatal("expected error") + } else { + assertDiagnosticSummary(t, diags, "Invalid version constraint") + } +} + +func TestModuleInstaller_invalidVersionConstraintLocal(t *testing.T) { + fixtureDir := filepath.Clean("test-fixtures/invalid-version-constraint-local") + dir, done := tempChdir(t, fixtureDir) + defer done() + + hooks := &testInstallHooks{} + + modulesDir := filepath.Join(dir, ".terraform/modules") + inst := NewModuleInstaller(modulesDir, nil) + _, diags := inst.InstallModules(".", false, hooks) + + if !diags.HasErrors() { + t.Fatal("expected error") + } else { + assertDiagnosticSummary(t, diags, "Invalid version constraint") + } +} + func TestModuleInstaller_symlink(t *testing.T) { fixtureDir := filepath.Clean("test-fixtures/local-module-symlink") dir, done := tempChdir(t, fixtureDir) diff --git a/internal/initwd/test-fixtures/invalid-version-constraint-local/.gitignore b/internal/initwd/test-fixtures/invalid-version-constraint-local/.gitignore new file mode 100644 index 000000000..6e0db03a8 --- /dev/null +++ b/internal/initwd/test-fixtures/invalid-version-constraint-local/.gitignore @@ -0,0 +1 @@ +.terraform/* diff --git a/internal/initwd/test-fixtures/invalid-version-constraint-local/root.tf b/internal/initwd/test-fixtures/invalid-version-constraint-local/root.tf new file mode 100644 index 000000000..e7dbaa323 --- /dev/null +++ b/internal/initwd/test-fixtures/invalid-version-constraint-local/root.tf @@ -0,0 +1,9 @@ +# This fixture references the github repo at: +# https://github.com/hashicorp/terraform-aws-module-installer-acctest +# However, due to the nature of this test (verifying early error), the URL will not be contacted, +# and the test is safe to execute as part of the normal test suite. + +module "acctest_root" { + source = "github.com/hashicorp/terraform-aws-module-installer-acctest" + version = "0.0.1" +} \ No newline at end of file diff --git a/internal/initwd/test-fixtures/invalid-version-constraint/root.tf b/internal/initwd/test-fixtures/invalid-version-constraint/root.tf index e7dbaa323..a973dd02f 100644 --- a/internal/initwd/test-fixtures/invalid-version-constraint/root.tf +++ b/internal/initwd/test-fixtures/invalid-version-constraint/root.tf @@ -1,9 +1,4 @@ -# This fixture references the github repo at: -# https://github.com/hashicorp/terraform-aws-module-installer-acctest -# However, due to the nature of this test (verifying early error), the URL will not be contacted, -# and the test is safe to execute as part of the normal test suite. - -module "acctest_root" { - source = "github.com/hashicorp/terraform-aws-module-installer-acctest" - version = "0.0.1" -} \ No newline at end of file +module "local" { + source = "./local" + version = "0.0.1" # Version constraint not allowed for a local module +}