-
Notifications
You must be signed in to change notification settings - Fork 0
/
completion_test.go
34 lines (30 loc) · 1.04 KB
/
completion_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cliz
import (
"bytes"
"context"
"testing"
"github.com/hakadoriya/z.go/testingz/assertz"
"github.com/hakadoriya/z.go/testingz/requirez"
)
//nolint:paralleltest
func TestCommand_initAppendCompletionSubCommand(t *testing.T) {
t.Run("success,", func(t *testing.T) {
c := newTestCommand()
buf := new(bytes.Buffer)
c.SetStdout(buf)
c.SetStderr(buf)
err := c.Exec(context.Background(), []string{"main-cli", "completion", "bash"})
requirez.NoError(t, err)
assertz.StringContains(t, buf.String(), c.Name)
assertz.StringContains(t, buf.String(), DefaultCompletionSubCommandName)
assertz.StringContains(t, buf.String(), DefaultGenerateBashCompletionSubCommandName)
})
t.Run("failure,open_invalid_file_does_not_exist", func(t *testing.T) {
c := newTestCommand()
backup := completionBashTmpl
t.Cleanup(func() { completionBashTmpl = backup })
completionBashTmpl = "invalid"
err := c.Exec(context.Background(), []string{"main-cli", "completion", "bash"})
requirez.ErrorContains(t, err, `open invalid: file does not exist`)
})
}