MCPcopy Create free account
hub / github.com/github/gh-aw / TestUninstallShellCompletion

Function TestUninstallShellCompletion

pkg/cli/shell_completion_test.go:319–415  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestUninstallShellCompletion(t *testing.T) {
320 // Save original environment
321 originalShell := os.Getenv("SHELL")
322 originalHome := os.Getenv("HOME")
323
324 // Restore environment after test
325 defer func() {
326 os.Setenv("SHELL", originalShell)
327 os.Setenv("HOME", originalHome)
328 }()
329
330 // Create a temporary home directory
331 tmpDir := t.TempDir()
332 os.Setenv("HOME", tmpDir)
333
334 tests := []struct {
335 name string
336 shellEnv string
337 setupFunc func(t *testing.T, tmpDir string)
338 expectError bool
339 errorMessage string
340 }{
341 {
342 name: "bash uninstall success",
343 shellEnv: "/bin/bash",
344 setupFunc: func(t *testing.T, tmpDir string) {
345 completionDir := tmpDir + "/.bash_completion.d"
346 err := os.MkdirAll(completionDir, 0750)
347 require.NoError(t, err)
348 err = os.WriteFile(completionDir+"/gh-aw", []byte("# test"), 0600)
349 require.NoError(t, err)
350 },
351 expectError: false,
352 },
353 {
354 name: "zsh uninstall success",
355 shellEnv: "/bin/zsh",
356 setupFunc: func(t *testing.T, tmpDir string) {
357 completionDir := tmpDir + "/.zsh/completions"
358 err := os.MkdirAll(completionDir, 0750)
359 require.NoError(t, err)
360 err = os.WriteFile(completionDir+"/_gh-aw", []byte("# test"), 0600)
361 require.NoError(t, err)
362 },
363 expectError: false,
364 },
365 {
366 name: "fish uninstall success",
367 shellEnv: "/usr/bin/fish",
368 setupFunc: func(t *testing.T, tmpDir string) {
369 completionDir := tmpDir + "/.config/fish/completions"
370 err := os.MkdirAll(completionDir, 0750)
371 require.NoError(t, err)
372 err = os.WriteFile(completionDir+"/gh-aw.fish", []byte("# test"), 0600)
373 require.NoError(t, err)
374 },
375 expectError: false,
376 },

Callers

nothing calls this directly

Calls 5

UninstallShellCompletionFunction · 0.85
GetenvMethod · 0.80
SetenvMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected