-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
51 lines (43 loc) · 965 Bytes
/
main_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
package main
import (
"errors"
"testing"
"github.com/spf13/cobra"
. "gopkg.in/check.v1"
"github.com/wizardsoftheweb/git-wiz/cmd"
)
func TestRootMain(t *testing.T) { TestingT(t) }
type MainSuite struct {
errorMessage string
}
var _ = Suite(&MainSuite{})
func (s *MainSuite) TestMain(c *C) {
var oldGitWizCmd = &cobra.Command{}
*oldGitWizCmd = *cmd.GitWizCmd
dummy := func(cmd *cobra.Command, args []string) {}
cmd.GitWizCmd.SilenceErrors = true
cmd.GitWizCmd.DisableFlagParsing = true
cmd.GitWizCmd.PersistentPreRun = dummy
cmd.GitWizCmd.PreRun = dummy
cmd.GitWizCmd.Run = dummy
cmd.GitWizCmd.PostRun = dummy
cmd.GitWizCmd.PersistentPostRun = dummy
c.Assert(
func() {
main()
},
Not(PanicMatches),
"*",
)
*cmd.GitWizCmd = *oldGitWizCmd
}
func (s *MainSuite) TestWhereErrorsGoToDie(c *C) {
s.errorMessage = "qqq"
c.Assert(
func() {
whereErrorsGoToDie(errors.New(s.errorMessage))
},
PanicMatches,
s.errorMessage,
)
}