-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli_version_handler_test.go
54 lines (46 loc) · 1.31 KB
/
cli_version_handler_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
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/urfave/cli"
)
type CLIVersionHandlerTestSuite struct {
suite.Suite
mockApp *cli.App
mockContext *cli.Context
}
func TestCLIVersionHandler(t *testing.T) {
suite.Run(t, new(CLIVersionHandlerTestSuite))
}
func (s *CLIVersionHandlerTestSuite) SetupTest() {
s.mockApp = cli.NewApp()
s.mockApp.Flags = getVersionFlags()
s.mockContext = cli.NewContext(s.mockApp, nil, nil)
}
func (s *CLIVersionHandlerTestSuite) Test_getVersionCommand() {
config := Config{}
logger := InitLogger(&LoggerConfig{Name: "getVersionCommand", Format: "raw", Level: "trace"})
command := getVersionCommand(&config, logger)
ensureCLICommand(s.T(), command, []string{"version", "v"}, getVersionFlags())
}
func (s *CLIVersionHandlerTestSuite) Test_getVersionFlags() {
ensureCLIFlags(s.T(),
[]string{
"commit",
"semver",
},
getVersionFlags(),
)
}
func (s *CLIVersionHandlerTestSuite) Test_getVersionAction() {
t := s.T()
config := Config{}
logger := InitLogger(&LoggerConfig{Name: "getVersionAction", Format: "raw", Level: "trace"})
s.mockApp.Action = getVersionAction(&config, logger)
if err := s.mockApp.Run([]string{"test-run-version"}); err == nil {
assert.True(t, config.RunVersion)
} else {
panic(err)
}
}