-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathpath_test.go
More file actions
95 lines (90 loc) · 2.19 KB
/
path_test.go
File metadata and controls
95 lines (90 loc) · 2.19 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
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
package ecrpublic
import "testing"
func TestIsHost(t *testing.T) {
tests := map[string]struct {
host string
expIs bool
}{
"an empty host should be false": {
host: "",
expIs: false,
},
"random string should be false": {
host: "foobar",
expIs: false,
},
"path with two segments should be false": {
host: "joshvanl/version-checker",
expIs: false,
},
"path with three segments should be false": {
host: "jetstack/joshvanl/version-checker",
expIs: false,
},
"random string with dots should be false": {
host: "foobar.foo",
expIs: false,
},
"docker.io should be false": {
host: "docker.io",
expIs: false,
},
"docker.com should be false": {
host: "docker.com",
expIs: false,
},
"just public.ecr.aws should be true": {
host: "public.ecr.aws",
expIs: true,
},
"public.ecr.aws.foo should be false": {
host: "public.ecr.aws.foo",
expIs: false,
},
"foo.public.ecr.aws should be false": {
host: "foo.public.ecr.aws",
expIs: false,
},
}
handler := new(Client)
for name, test := range tests {
t.Run(name, func(t *testing.T) {
if isHost := handler.IsHost(test.host); isHost != test.expIs {
t.Errorf("%s: unexpected IsHost, exp=%t got=%t",
test.host, test.expIs, isHost)
}
})
}
}
func TestRepoImageFromPath(t *testing.T) {
tests := map[string]struct {
path string
expRepo, expImage string
}{
"single image should return registry and image": {
path: "nginx",
expRepo: "nginx",
expImage: "",
},
"two segments to path should return registry and repo": {
path: "eks-distro/kubernetes",
expRepo: "eks-distro",
expImage: "kubernetes",
},
"three segments to path should return registry and combined repo": {
path: "eks-distro/kubernetes/kube-proxy",
expRepo: "eks-distro",
expImage: "kubernetes/kube-proxy",
},
}
handler := new(Client)
for name, test := range tests {
t.Run(name, func(t *testing.T) {
repo, image := handler.RepoImageFromPath(test.path)
if repo != test.expRepo || image != test.expImage {
t.Errorf("%s: unexpected repo/image, exp=%s/%s got=%s/%s",
test.path, test.expRepo, test.expImage, repo, image)
}
})
}
}