-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
57 lines (54 loc) · 1.31 KB
/
command_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
package cmd_toolkit_test
import (
cmdtoolkit "github.com/majohn-r/cmd-toolkit"
"testing"
"github.com/majohn-r/output"
)
func TestLogCommandStart(t *testing.T) {
type args struct {
name string
m map[string]any
}
tests := map[string]struct {
args
output.WantedRecording
}{
"bad map": {
args: args{name: "nasty command", m: nil},
WantedRecording: output.WantedRecording{
Log: "level='info' command='nasty command' msg='executing command'\n",
},
},
"empty map": {
args: args{name: "niceCommand", m: map[string]any{}},
WantedRecording: output.WantedRecording{
Log: "level='info' command='niceCommand' msg='executing command'\n",
},
},
"busy map": {
args: args{
name: "", // note, this is ignored because the map contains a "command" entry
m: map[string]any{
"command": "BusyCommand",
"-flag1": "value1",
"-flag2": 25,
},
},
WantedRecording: output.WantedRecording{
Log: "" +
"level='info'" +
" -flag1='value1'" +
" -flag2='25'" +
" command='BusyCommand'" +
" msg='executing command'\n",
},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
o := output.NewRecorder()
cmdtoolkit.LogCommandStart(o, tt.args.name, tt.args.m)
o.Report(t, "LogCommandStart()", tt.WantedRecording)
})
}
}