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

Code before:
		{
			name:           "deeply nested missing with existing parent",
			path:           filepath.Join(nestedExistingDir, "missing"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "multiple missing levels",
			path:           filepath.Join(existingDir, "missing", "also", "missingtoo"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "completely non-existent path",
			path:           filepath.Join(tmpDir, "completely", "missing", "path"),
			wantExists:     true,
			wantMissingDir: "completely",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotExists, gotMissingDir := isSubDirNonExistent(tt.path)

			if gotExists != tt.wantExists {
				t.Errorf("isSubDirNonExistant() exists = %v, want %v", gotExists, tt.wantExists)
			}
			if gotMissingDir != tt.wantMissingDir {
				t.Errorf("isSubDirNonExistant() missingDir = %q, want %q", gotMissingDir, tt.wantMissingDir)
			}
		})
	}
}

// TestModuleInstaller_nonExistentSubmodule ensures that the error message returned when a module does not exist in an existing module
// is not that it's a bug in OpenTofu. See issue https://github.com/opentofu/opentofu/issues/3142 for more information
//
// Code is taken from tests above
func TestModuleInstaller_nonExistentSubmodule(t *testing.T) {
	if os.Getenv("TF_ACC") == "" {
		t.Skip("this test accesses github.com; set TF_ACC=1 to run it")
	}

	fixtureDir := filepath.Clean("testdata/submodule-non-existent")
	tmpDir := tempChdir(t, fixtureDir)

	// the module installer runs filepath.EvalSymlinks() on the destination
	// directory before copying files, and the resultant directory is what is
	// returned by the install hooks. Without this, tests could fail on machines
	// where the default temp dir was a symlink.
	dir, err := filepath.EvalSymlinks(tmpDir)

Review comment (suggestion):
```suggestion
				t.Errorf("isSubDirNonExistent() exists = %v, want %v", gotExists, tt.wantExists)
```

Code after:
		{
			name:           "deeply nested missing with existing parent",
			path:           filepath.Join(nestedExistingDir, "missing"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "multiple missing levels",
			path:           filepath.Join(existingDir, "missing", "also", "missingtoo"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "completely non-existent path",
			path:           filepath.Join(tmpDir, "completely", "missing", "path"),
			wantExists:     true,
			wantMissingDir: "completely",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotExists, gotMissingDir := isSubDirNonExistent(tt.path)

			if gotExists != tt.wantExists {
				t.Errorf("isSubDirNonExistent() exists = %v, want %v", gotExists, tt.wantExists)
			}
			if gotMissingDir != tt.wantMissingDir {
				t.Errorf("isSubDirNonExistent() missingDir = %q, want %q", gotMissingDir, tt.wantMissingDir)
			}
		})
	}
}

// TestModuleInstaller_nonExistentSubmodule ensures that the error message returned when a module does not exist in an existing module
// is not that it's a bug in OpenTofu. See issue https://github.com/opentofu/opentofu/issues/3142 for more information
//
// Code is taken from tests above
func TestModuleInstaller_nonExistentSubmodule(t *testing.T) {
	if os.Getenv("TF_ACC") == "" {
		t.Skip("this test accesses github.com; set TF_ACC=1 to run it")
	}

	fixtureDir := filepath.Clean("testdata/submodule-non-existent")
	tmpDir := tempChdir(t, fixtureDir)

	// the module installer runs filepath.EvalSymlinks() on the destination
	// directory before copying files, and the resultant directory is what is
	// returned by the install hooks. Without this, tests could fail on machines
	// where the default temp dir was a symlink.
	dir, err := filepath.EvalSymlinks(tmpDir)