forked from Praqma/helmsman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
111 lines (107 loc) · 2.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"strings"
"testing"
)
// func Test_command_printDescription(t *testing.T) {
// type fields struct {
// Cmd string
// Args []string
// Description string
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// c := command{
// Cmd: tt.fields.Cmd,
// Args: tt.fields.Args,
// Description: tt.fields.Description,
// }
// c.printDescription()
// })
// }
// }
// func Test_command_printFullCommand(t *testing.T) {
// type fields struct {
// Cmd string
// Args []string
// Description string
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// c := command{
// Cmd: tt.fields.Cmd,
// Args: tt.fields.Args,
// Description: tt.fields.Description,
// }
// c.printFullCommand()
// })
// }
// }
func Test_command_exec(t *testing.T) {
type fields struct {
Cmd string
Args []string
Description string
}
type args struct {
debug bool
verbose bool
}
tests := []struct {
name string
fields fields
args args
want int
want1 string
}{
{
name: "echo",
fields: fields{
Cmd: "bash",
Args: []string{"-c", "echo this is fun"},
Description: "A bash command execution test with echo.",
},
args: args{debug: false, verbose: false},
want: 0,
want1: "this is fun",
}, {
name: "exitCode",
fields: fields{
Cmd: "bash",
Args: []string{"-c", "echo $?"},
Description: "A bash command execution test with exitCode.",
},
args: args{debug: false},
want: 0,
want1: "0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := command{
Cmd: tt.fields.Cmd,
Args: tt.fields.Args,
Description: tt.fields.Description,
}
got, got1 := c.exec(tt.args.debug, tt.args.verbose)
if got != tt.want {
t.Errorf("command.exec() got = %v, want %v", got, tt.want)
}
if strings.TrimSpace(got1) != tt.want1 {
t.Errorf("command.exec() got1 = %v, want %v", got1, tt.want1)
}
})
}
}