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

Code before:
			name:           "nested directory exists",
			path:           nestedExistingDir,
			wantExists:     false,
			wantMissingDir: "",
		},
		{
			name:           "single missing directory with existing parent",
			path:           filepath.Join(existingDir, "missing"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "nested missing directory",
			path:           filepath.Join(existingDir, "missing", "nested"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			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", "missing"),
			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)
			}
		})
	}
}


Review comment (suggestion):
```suggestion
			path:           filepath.Join(existingDir, "missing", "also", "missingtoo"),
```
Just to remove the confusion from `wantMissingDir`

Code after:
			name:           "nested directory exists",
			path:           nestedExistingDir,
			wantExists:     false,
			wantMissingDir: "",
		},
		{
			name:           "single missing directory with existing parent",
			path:           filepath.Join(existingDir, "missing"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			name:           "nested missing directory",
			path:           filepath.Join(existingDir, "missing", "nested"),
			wantExists:     true,
			wantMissingDir: "missing",
		},
		{
			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)
			}
		})
	}
}