-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathutils_test.go
More file actions
55 lines (50 loc) · 1.23 KB
/
utils_test.go
File metadata and controls
55 lines (50 loc) · 1.23 KB
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
package utils
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestParseScriptParams(t *testing.T) {
tests := []struct {
description string
input *map[string]string
expectedOutput *map[string]string
isValid bool
}{
{
description: "base-ok",
input: &map[string]string{"script": "ls /"},
expectedOutput: &map[string]string{"script": "ls /"},
isValid: true,
},
{
description: "nil input",
input: nil,
expectedOutput: nil,
isValid: true,
},
{
description: "not-ok-nonexistant-file-specified-for-script",
input: &map[string]string{"script": "@{/some/file/which/does/not/exist/and/thus/fails}"},
expectedOutput: nil,
isValid: false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output, err := ParseScriptParams(tt.input)
if tt.isValid && err != nil {
t.Errorf("failed on valid input")
}
if !tt.isValid && err == nil {
t.Errorf("did not fail on invalid input")
}
if !tt.isValid {
return
}
diff := cmp.Diff(output, tt.expectedOutput)
if diff != "" {
t.Fatalf("ParseScriptParams() output mismatch (-want +got):\n%s", diff)
}
})
}
}