-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_test.go
62 lines (50 loc) · 1.13 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"os"
"testing"
"github.com/urfave/cli"
)
func Test(t *testing.T) {
osExiterOriginal := cli.OsExiter
defer func() { cli.OsExiter = osExiterOriginal }()
logFatalOriginal := logFatal
defer func() { logFatal = logFatalOriginal }()
tests := []struct {
title string
experr bool
args []string
}{
{
title: "success",
experr: false,
args: []string{"-h"},
},
{
title: "error",
experr: true,
args: []string{"not-existent"},
},
}
// mock cli.OsExiter
exitCode := 0
cli.OsExiter = func(code int) {
exitCode = code
}
// mock logFatal
logFatal = func(...interface{}) {}
for _, tt := range tests {
t.Run(tt.title, func(t *testing.T) {
args := make([]string, 0, len(tt.args)+1)
args = append(args, "eskip-match")
args = append(args, tt.args...)
os.Args = args
main()
if exitCode > 0 && !tt.experr {
t.Errorf("expected process exiting with success but an error occurred, exit code is = %d", exitCode)
}
if exitCode == 0 && tt.experr {
t.Errorf("expected process exiting with error but got success, exit code is = %d", exitCode)
}
})
}
}