forked from src-d/go-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_test.go
96 lines (81 loc) · 1.59 KB
/
log_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cli
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
type LogCommand struct {
Command `name:"nop" short-description:"nop" long-description:"nop"`
}
func (c *LogCommand) Execute(args []string) error {
return nil
}
func setupLogCommand(t *testing.T) *App {
app := New("test", "", "", "")
app.AddCommand(&LogCommand{})
return app
}
func TestLogLevel(t *testing.T) {
fixtures := []struct {
level string
err bool
}{{
level: "info",
err: false,
}, {
level: "debug",
err: false,
}, {
level: "warning",
err: false,
}, {
level: "error",
err: false,
}, {
level: "other",
err: true,
}}
app := setupLogCommand(t)
for _, fixture := range fixtures {
t.Run(fixture.level, func(t *testing.T) {
require := require.New(t)
err := app.Run([]string{"test", "nop",
fmt.Sprintf("--log-level=%s", fixture.level)})
if fixture.err {
require.NotNil(err)
require.Contains(err.Error(), "Invalid value")
} else {
require.NoError(err)
}
})
}
}
func TestLogFormat(t *testing.T) {
fixtures := []struct {
format string
err bool
}{{
format: "text",
err: false,
}, {
format: "json",
err: false,
}, {
format: "txt",
err: true,
}}
app := setupLogCommand(t)
for _, fixture := range fixtures {
t.Run(fixture.format, func(t *testing.T) {
require := require.New(t)
err := app.Run([]string{"test", "nop",
fmt.Sprintf("--log-format=%s", fixture.format)})
if fixture.err {
require.NotNil(err)
require.Contains(err.Error(), "Invalid value")
} else {
require.NoError(err)
}
})
}
}