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:
James Bardin
2023-08-03 16:53:53 -04:00
parent 29c3f650cd
commit 09d91eb675
3 changed files with 47 additions and 1 deletions

View File

@@ -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