-
Notifications
You must be signed in to change notification settings - Fork 14
/
commands_test.go
42 lines (33 loc) · 940 Bytes
/
commands_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
35
36
37
38
39
40
41
42
package cmd
import (
"os"
"rare/pkg/testutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
)
func TestCommandGetter(t *testing.T) {
assert.NotNil(t, GetSupportedCommands())
}
func testCommandSet(t *testing.T, command *cli.Command, commandArgList ...string) {
for _, args := range commandArgList {
assert.NoError(t, testCommand(command, args))
}
}
func testCommandCapture(command *cli.Command, cmd string) (stdout, stderr string, err error) {
return testutil.Capture(func(w *os.File) error {
return testCommand(command, cmd)
})
}
func testCommand(command *cli.Command, cmd string) error {
app := cli.NewApp()
command.Name = "_testcommand"
app.Commands = []*cli.Command{
command,
}
app.ExitErrHandler = func(context *cli.Context, err error) {
// disabled
}
commandArgs := append([]string{"app", "_testcommand"}, testutil.SplitQuotedString(cmd)...)
return app.Run(commandArgs)
}