| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/ipfs/kubo/test/cli/harness" |
| 8 | . "github.com/ipfs/kubo/test/cli/testutils" |
| 9 | "github.com/stretchr/testify/assert" |
| 10 | ) |
| 11 | |
| 12 | func TestBashCompletion(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | h := harness.NewT(t) |
| 15 | node := h.NewNode() |
| 16 | |
| 17 | res := node.IPFS("commands", "completion", "bash") |
| 18 | |
| 19 | length := len(res.Stdout.String()) |
| 20 | if length < 100 { |
| 21 | t.Fatalf("expected a long Bash completion file, but got one of length %d", length) |
| 22 | } |
| 23 | |
| 24 | t.Run("completion file can be loaded in bash", func(t *testing.T) { |
| 25 | RequiresLinux(t) |
| 26 | |
| 27 | completionFile := h.WriteToTemp(res.Stdout.String()) |
| 28 | res = h.Sh(fmt.Sprintf("source %s && type -t _ipfs", completionFile)) |
| 29 | assert.NoError(t, res.Err) |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | func TestZshCompletion(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | h := harness.NewT(t) |
| 36 | node := h.NewNode() |
| 37 | |
| 38 | res := node.IPFS("commands", "completion", "zsh") |
| 39 | |
| 40 | length := len(res.Stdout.String()) |
| 41 | if length < 100 { |
| 42 | t.Fatalf("expected a long Bash completion file, but got one of length %d", length) |
| 43 | } |
| 44 | |
| 45 | t.Run("completion file can be loaded in bash", func(t *testing.T) { |
| 46 | RequiresLinux(t) |
| 47 | |
| 48 | completionFile := h.WriteToTemp(res.Stdout.String()) |
| 49 | res = h.Runner.Run(harness.RunRequest{ |
| 50 | Path: "zsh", |
| 51 | Args: []string{"-c", fmt.Sprintf("autoload -Uz compinit && compinit && source %s && echo -E $_comps[ipfs]", completionFile)}, |
| 52 | }) |
| 53 | |
| 54 | assert.NoError(t, res.Err) |
| 55 | assert.NotEmpty(t, res.Stdout.String()) |
| 56 | }) |
| 57 | } |