From 7780f69bbdfa329be62ad97d9db1ea78aa8bae71 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 4 Dec 2025 15:51:01 -0800 Subject: [PATCH] initwd: Fix the TF_ACC=1 tests Earlier work in opentofu/opentofu#2661 caused the module installer to treat the registry client and the package fetcher as optional dependencies so that local-only tests (by far our common case across the whole codebase) could avoid instantiating the registry and go-getter client code and risk accidentally depending on network services. However, at the time I didn't notice that this package had TF_ACC=1 acceptance tests, and so although I made systematic updates across all the tests which appeared to make them pass there were actually several that were being skipped and so I didn't notice that I hadn't updated them well enough. This gets them all passing again by giving the ones that intentionally access the real OpenTofu Registry and some test-only GitHub repositories the clients they need to do that. In a future commit I intend to add this package to our end-to-end test job that runs as part of our pull request checks so that we're less likely to forget to update these tests under future maintenance. Signed-off-by: Martin Atkins --- internal/initwd/from_module_test.go | 3 ++- internal/initwd/module_install_test.go | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/initwd/from_module_test.go b/internal/initwd/from_module_test.go index ed1127c852..1af2602076 100644 --- a/internal/initwd/from_module_test.go +++ b/internal/initwd/from_module_test.go @@ -45,8 +45,9 @@ func TestDirFromModule_registry(t *testing.T) { hooks := &testInstallHooks{} reg := registry.NewClient(t.Context(), nil, nil) + fetcher := getmodules.NewPackageFetcher(t.Context(), nil) loader := configload.NewLoaderForTests(t) - diags := DirFromModule(context.Background(), loader, dir, modsDir, "hashicorp/module-installer-acctest/aws//examples/main", reg, nil, hooks) + diags := DirFromModule(t.Context(), loader, dir, modsDir, "hashicorp/module-installer-acctest/aws//examples/main", reg, fetcher, hooks) assertNoDiagnostics(t, diags) v := version.Must(version.NewVersion("0.0.2")) diff --git a/internal/initwd/module_install_test.go b/internal/initwd/module_install_test.go index 5249d36dba..2f949ea251 100644 --- a/internal/initwd/module_install_test.go +++ b/internal/initwd/module_install_test.go @@ -305,7 +305,9 @@ func TestModuleInstaller_Prerelease(t *testing.T) { modulesDir := filepath.Join(dir, ".terraform/modules") loader := configload.NewLoaderForTests(t) - inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(t.Context(), nil, nil), nil) + reg := registry.NewClient(t.Context(), nil, nil) + fetcher := getmodules.NewPackageFetcher(t.Context(), nil) + inst := NewModuleInstaller(modulesDir, loader, reg, fetcher) cfg, diags := inst.InstallModules(context.Background(), ".", "tests", false, false, hooks, configs.RootModuleCallForTesting()) if tc.shouldError { @@ -480,7 +482,9 @@ func TestLoaderInstallModules_registry(t *testing.T) { modulesDir := filepath.Join(dir, ".terraform/modules") loader := configload.NewLoaderForTests(t) - inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(t.Context(), nil, nil), nil) + reg := registry.NewClient(t.Context(), nil, nil) + fetcher := getmodules.NewPackageFetcher(t.Context(), nil) + inst := NewModuleInstaller(modulesDir, loader, reg, fetcher) _, diags := inst.InstallModules(context.Background(), dir, "tests", false, false, hooks, configs.RootModuleCallForTesting()) assertNoDiagnostics(t, diags) @@ -640,7 +644,9 @@ func TestLoaderInstallModules_goGetter(t *testing.T) { modulesDir := filepath.Join(dir, ".terraform/modules") loader := configload.NewLoaderForTests(t) - inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(t.Context(), nil, nil), nil) + reg := registry.NewClient(t.Context(), nil, nil) + fetcher := getmodules.NewPackageFetcher(t.Context(), nil) + inst := NewModuleInstaller(modulesDir, loader, reg, fetcher) _, diags := inst.InstallModules(context.Background(), dir, "tests", false, false, hooks, configs.RootModuleCallForTesting()) assertNoDiagnostics(t, diags) @@ -809,7 +815,9 @@ func TestLoadInstallModules_registryFromTest(t *testing.T) { modulesDir := filepath.Join(dir, ".terraform/modules") loader := configload.NewLoaderForTests(t) - inst := NewModuleInstaller(modulesDir, loader, registry.NewClient(t.Context(), nil, nil), nil) + reg := registry.NewClient(t.Context(), nil, nil) + fetcher := getmodules.NewPackageFetcher(t.Context(), nil) + inst := NewModuleInstaller(modulesDir, loader, reg, fetcher) _, diags := inst.InstallModules(context.Background(), dir, "tests", false, false, hooks, configs.RootModuleCallForTesting()) assertNoDiagnostics(t, diags)