diff --git a/pkg/cmd/codespace/ssh_test.go b/pkg/cmd/codespace/ssh_test.go index 3f2a8a23b..adad394d3 100644 --- a/pkg/cmd/codespace/ssh_test.go +++ b/pkg/cmd/codespace/ssh_test.go @@ -26,12 +26,6 @@ func TestPendingOperationDisallowsSSH(t *testing.T) { } func TestAutomaticSSHKeyPairs(t *testing.T) { - dir := t.TempDir() - - sshContext := ssh.Context{ - ConfigDir: dir, - } - tests := []struct { // These files exist when calling setupAutomaticSSHKeys existingFiles []string @@ -71,15 +65,14 @@ func TestAutomaticSSHKeyPairs(t *testing.T) { } for _, tt := range tests { - err := os.RemoveAll(dir) - if err != nil { - t.Errorf("Failed to clean test directory: %v", err) - } - err = os.MkdirAll(dir, 0711) - if err != nil { - t.Errorf("Failed to set up test directory: %v", err) + dir := t.TempDir() + + sshContext := ssh.Context{ + ConfigDir: dir, } + defer os.RemoveAll(dir) + for _, file := range tt.existingFiles { if _, err := os.Create(filepath.Join(dir, file)); err != nil { t.Errorf("Failed to setup test files: %v", err)