Repository: opentofu/opentofu
File: internal/initwd/module_install_test.go (Go)

Code before:
	}
	if _, ok := inst.registryPackageVersions[packageAddr]; !ok {
		t.Errorf("module versions cache was not populated\ngot: %s\nwant: key hashicorp/module-installer-acctest/aws", spew.Sdump(inst.registryPackageVersions))
	}
	if _, ok := inst.registryPackageSources[moduleVersion{module: packageAddr, version: "0.0.1"}]; !ok {
		t.Errorf("module download url cache was not populated\ngot: %s", spew.Sdump(inst.registryPackageSources))
	}

	loader, err = configload.NewLoader(&configload.Config{
		ModulesDir: modulesDir,
	})
	if err != nil {
		t.Fatal(err)
	}

	// Make sure the configuration is loadable now.
	// (This ensures that correct information is recorded in the manifest.)
	config, loadDiags := loader.LoadConfigWithTests(t.Context(), ".", "tests", configs.RootModuleCallForTesting())
	assertNoDiagnostics(t, tfdiags.Diagnostics{}.Append(loadDiags))

	if config.Module.Tests["main.tftest.hcl"].Runs[0].ConfigUnderTest == nil {
		t.Fatalf("should have loaded config into the relevant run block but did not")
	}
}

func TestIsSubDirNonExistant(t *testing.T) {
	tmpDir := t.TempDir()

	// Create test directory structure
	existingDir := filepath.Join(tmpDir, "existing")
	nestedExistingDir := filepath.Join(existingDir, "nested", "deep")
	err := os.MkdirAll(nestedExistingDir, 0o755)
	if err != nil {
		t.Fatal(err)
	}

	tests := []struct {
		name           string
		path           string
		wantExists     bool
		wantMissingDir string
	}{
		{
			name:           "directory exists",
			path:           existingDir,
			wantExists:     false,
			wantMissingDir: "",
		},
		{
			name:           "nested directory exists",
			path:           nestedExistingDir,

Review comment (suggestion):
```suggestion
func TestIsSubDirNonExistent(t *testing.T) {
```

Code after:
	}
	if _, ok := inst.registryPackageVersions[packageAddr]; !ok {
		t.Errorf("module versions cache was not populated\ngot: %s\nwant: key hashicorp/module-installer-acctest/aws", spew.Sdump(inst.registryPackageVersions))
	}
	if _, ok := inst.registryPackageSources[moduleVersion{module: packageAddr, version: "0.0.1"}]; !ok {
		t.Errorf("module download url cache was not populated\ngot: %s", spew.Sdump(inst.registryPackageSources))
	}

	loader, err = configload.NewLoader(&configload.Config{
		ModulesDir: modulesDir,
	})
	if err != nil {
		t.Fatal(err)
	}

	// Make sure the configuration is loadable now.
	// (This ensures that correct information is recorded in the manifest.)
	config, loadDiags := loader.LoadConfigWithTests(t.Context(), ".", "tests", configs.RootModuleCallForTesting())
	assertNoDiagnostics(t, tfdiags.Diagnostics{}.Append(loadDiags))

	if config.Module.Tests["main.tftest.hcl"].Runs[0].ConfigUnderTest == nil {
		t.Fatalf("should have loaded config into the relevant run block but did not")
	}
}

func TestIsSubDirNonExistent(t *testing.T) {
	tmpDir := t.TempDir()

	// Create test directory structure
	existingDir := filepath.Join(tmpDir, "existing")
	nestedExistingDir := filepath.Join(existingDir, "nested", "deep")
	err := os.MkdirAll(nestedExistingDir, 0o755)
	if err != nil {
		t.Fatal(err)
	}

	tests := []struct {
		name           string
		path           string
		wantExists     bool
		wantMissingDir string
	}{
		{
			name:           "directory exists",
			path:           existingDir,
			wantExists:     false,
			wantMissingDir: "",
		},
		{
			name:           "nested directory exists",
			path:           nestedExistingDir,