forked from helmfile/chartify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
91 lines (85 loc) · 1.85 KB
/
util_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
package chartify
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCreateFlagChain(t *testing.T) {
testcases := []struct {
flag string
values []string
expect string
}{
{
flag: "foo",
values: []string{"1"},
expect: " --foo 1",
},
{
flag: "foo",
values: []string{"1", "2"},
expect: " --foo 1 --foo 2",
},
{
flag: "f",
values: []string{"a"},
expect: " -f a",
},
{
flag: "f",
values: []string{"a", "b"},
expect: " -f a -f b",
},
}
for i, tc := range testcases {
actual := createFlagChain(tc.flag, tc.values)
if diff := cmp.Diff(tc.expect, actual); diff != "" {
t.Errorf("case %d:\n%s", i, diff)
}
}
}
// TestFindSemVerInfo tests the FindSemVerInfo function.
func TestFindSemVerInfo(t *testing.T) {
tests := []struct {
name string
version string
want string
wantErr bool
}{
{
name: "valid semver for v4",
version: "{Version:kustomize/v4.5.7 GitCommit:56d82a8378dfc8dc3b3b1085e5a6e67b82966bd7 BuildDate:2022-08-02T16:35:54Z GoOs:darwin GoArch:arm64}",
want: "v4.5.7",
wantErr: false,
},
{
name: "valid semver for v3",
version: "{Version:kustomize/v3.10.0 GitCommit:602ad8aa98e2e17f6c9119e027a09757e63c8bec BuildDate:2021-02-10T00:00:50Z GoOs:linux GoArch:amd64}",
want: "v3.10.0",
wantErr: false,
},
{
name: "invalid semver",
version: "version",
want: "",
wantErr: true,
},
{
name: "valid semver for v5",
version: "v5.0.0",
want: "v5.0.0",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := FindSemVerInfo(tt.version)
if (err != nil) != tt.wantErr {
t.Errorf("FindSemVerInfo() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("FindSemVerInfo() = %v, want %v", got, tt.want)
}
})
}
}