-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
48 lines (43 loc) · 1.07 KB
/
helper_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
package iapetus
import (
"errors"
"os/exec"
"testing"
)
func TestGetExitCode(t *testing.T) {
tests := []struct {
name string
err error
expected int
}{
{"No error", nil, 0},
{"Exit error", &exec.ExitError{}, -1},
{"Non-exit error", errors.New("some error"), -1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getExitCode(tt.err); got != tt.expected {
t.Errorf("getExitCode() = %v, want %v", got, tt.expected)
}
})
}
}
func TestParseJSONOutputs(t *testing.T) {
tests := []struct {
name string
actual, expected string
wantErr bool
}{
{"Valid JSON", `{"key": "value"}`, `{"key": "value"}`, false},
{"Invalid actual JSON", `{"key": "value"`, `{"key": "value"}`, true},
{"Invalid expected JSON", `{"key": "value"}`, `{"key": "value"`, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, _, err := parseJSONOutputs(tt.actual, tt.expected)
if (err != nil) != tt.wantErr {
t.Errorf("parseJSONOutputs() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}