This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils_test.go
56 lines (49 loc) · 1.51 KB
/
utils_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
package main
import (
"testing"
"time"
)
func TestResultset_execCommand(t *testing.T) {
type fields struct {
OSCommand string
CommandArgs []string
Stdout string
Stderr string
CmdStarttime time.Time
CMDStoptime time.Time
DurationSecounds int
SuccessfullExecution bool
ErrorStr string
}
tests := []struct {
name string
fields fields
compare fields
}{
{"return 0", fields{OSCommand: "/usr/bin/true"}, fields{SuccessfullExecution: true}},
{"return 1", fields{OSCommand: "/usr/bin/false"}, fields{SuccessfullExecution: false}},
{"stdout", fields{OSCommand: "/bin/echo", CommandArgs: []string{"oh", "yeah"}},
fields{SuccessfullExecution: true, Stdout: "oh yeah\n"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &Resultset{
OSCommand: tt.fields.OSCommand,
CommandArgs: tt.fields.CommandArgs,
Stdout: tt.fields.Stdout,
Stderr: tt.fields.Stderr,
SuccessfullExecution: tt.fields.SuccessfullExecution,
ErrorStr: tt.fields.ErrorStr,
}
r.execCommand()
// switch debug on
if r.SuccessfullExecution != tt.compare.SuccessfullExecution {
t.Errorf("exec command failed: got: %v want: %v", tt.fields.SuccessfullExecution, tt.compare.SuccessfullExecution)
}
if r.Stdout != tt.compare.Stdout {
t.Errorf("execCommand() = got: ->%v<-, want ->%v<-", r.Stdout, tt.compare.Stdout)
}
},
)
}
}