mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
test -from-module with invalid root module
Add a test for `init -from-module` with a module which is not a valid root module.
This commit is contained in:
parent
29c3f650cd
commit
09d91eb675
@ -212,6 +212,38 @@ func TestDirFromModule_submodules(t *testing.T) {
|
||||
assertResultDeepEqual(t, gotTraces, wantTraces)
|
||||
}
|
||||
|
||||
// submodulesWithProvider is identical to above, except that the configuration
|
||||
// would fail to load for some reason. We still want the module to be installed
|
||||
// for use cases like testing or CDKTF, and will only emit warnings for config
|
||||
// errors.
|
||||
func TestDirFromModule_submodulesWithProvider(t *testing.T) {
|
||||
fixtureDir := filepath.Clean("testdata/empty")
|
||||
fromModuleDir, err := filepath.Abs("./testdata/local-module-missing-provider")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tmpDir, done := tempChdir(t, fixtureDir)
|
||||
defer done()
|
||||
|
||||
hooks := &testInstallHooks{}
|
||||
dir, err := filepath.EvalSymlinks(tmpDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
modInstallDir := filepath.Join(dir, ".terraform/modules")
|
||||
|
||||
loader, cleanup := configload.NewLoaderForTests(t)
|
||||
defer cleanup()
|
||||
diags := DirFromModule(context.Background(), loader, dir, modInstallDir, fromModuleDir, nil, hooks)
|
||||
|
||||
for _, d := range diags {
|
||||
if d.Severity() != tfdiags.Warning {
|
||||
t.Errorf("expected warning, got %v", diags.Err())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestDirFromModule_rel_submodules is similar to the test above, but the
|
||||
// from-module is relative to the install dir ("../"):
|
||||
// https://github.com/hashicorp/terraform/issues/23010
|
||||
|
@ -944,7 +944,7 @@ func assertNoDiagnostics(t *testing.T, diags tfdiags.Diagnostics) bool {
|
||||
|
||||
func assertDiagnosticCount(t *testing.T, diags tfdiags.Diagnostics, want int) bool {
|
||||
t.Helper()
|
||||
if len(diags) != 0 {
|
||||
if len(diags) != want {
|
||||
t.Errorf("wrong number of diagnostics %d; want %d", len(diags), want)
|
||||
for _, diag := range diags {
|
||||
t.Logf("- %#v", diag)
|
||||
|
14
internal/initwd/testdata/local-module-missing-provider/main.tf
vendored
Normal file
14
internal/initwd/testdata/local-module-missing-provider/main.tf
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
foo = {
|
||||
source = "hashicorp/foo"
|
||||
// since this module declares an alias with no config, it is not valid as
|
||||
// a root module.
|
||||
configuration_aliases = [ foo.alternate ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "foo_instance" "bam" {
|
||||
provider = foo.alternate
|
||||
}
|
Loading…
Reference in New Issue
Block a user