MCPcopy Create free account
hub / github.com/celer-pkg/celer / TestInstallAndUninstall_Bash

Function TestInstallAndUninstall_Bash

completion/bash_test.go:15–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestInstallAndUninstall_Bash(t *testing.T) {
16 if runtime.GOOS == "windows" {
17 t.Skip("bash is not supported on Windows")
18 }
19
20 var fileExists = func(path string) bool {
21 _, err := os.Stat(path)
22 return err == nil
23 }
24
25 home := t.TempDir()
26
27 // Set dirs.TmpFilesDir to a temp location specific for the test
28 origTmp := dirs.TmpFilesDir
29 tmpRoot := filepath.Join(t.TempDir(), "tmpfiles")
30 dirs.TmpFilesDir = tmpRoot
31 defer func() { dirs.TmpFilesDir = origTmp }()
32
33 rootCmd := &cobra.Command{
34 Use: "celer",
35 }
36 b := NewBashCompletion(home, rootCmd)
37
38 // Ensure clean tmp dir exists
39 if err := dirs.CleanTmpFilesDir(); err != nil {
40 t.Fatalf("CleanTmpFilesDir failed: %v", err)
41 }
42
43 // Install completion (should generate file in tmp then move it to destination)
44 if err := b.installCompletion(); err != nil {
45 t.Fatalf("installCompletion failed: %v", err)
46 }
47
48 dest := filepath.Join(home, ".local", "share", "bash-completion", "completions", "celer")
49 if !fileExists(dest) {
50 t.Fatalf("expected completion file at %s to exist", dest)
51 }
52
53 // Uninstall completion (should remove file and attempt to remove empty parent)
54 if err := b.uninstallCompletion(); err != nil {
55 t.Fatalf("uninstallCompletion failed: %v", err)
56 }
57 if fileExists(dest) {
58 t.Fatalf("expected completion file to be removed at %s", dest)
59 }
60
61 // parent dir might be removed; ensure it does not contain the file
62 parent := filepath.Dir(dest)
63 if fileExists(parent) {
64 // If parent still exists ensure it's not containing our file
65 if fileExists(filepath.Join(parent, "celer")) {
66 t.Fatalf("completion file still present after uninstall")
67 }
68 }
69}
70
71func TestRegisterAndUnregisterRunCommand_Bash(t *testing.T) {
72 home := t.TempDir()

Callers

nothing calls this directly

Calls 4

CleanTmpFilesDirFunction · 0.92
NewBashCompletionFunction · 0.85
installCompletionMethod · 0.65
uninstallCompletionMethod · 0.65

Tested by

no test coverage detected