-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathpath_test.go
More file actions
106 lines (100 loc) · 2.6 KB
/
path_test.go
File metadata and controls
106 lines (100 loc) · 2.6 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
96
97
98
99
100
101
102
103
104
105
106
package ecrpublic
import (
"testing"
"github.com/stretchr/testify/assert"
)
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,
},
"random string with dots should be false": {
host: "foobar.foo",
expIs: false,
},
"just amazonawsaws.com should be false": {
host: "amazonaws.com",
expIs: false,
},
"ecr.foo.amazonaws.com with random sub domains should be false": {
host: "bar.ecr.foo.amazonaws.com",
expIs: false,
},
"dkr.ecr.foo.amazonaws.com with random sub domains should be false": {
host: "dkr.ecr.foo.amazonaws.com",
expIs: false,
},
"hello123.dkr.ecr.foo.amazonaws.com false": {
host: "hello123.dkr.ecr.foo.amazonaws.com",
expIs: false,
},
"123hello.hello.dkr.ecr.foo.amazonaws.com false": {
host: "123hello.hello.dkr.ecr.foo.amazonaws.com",
expIs: false,
},
"123hello.dkr.ecr.foo.amazonaws.comfoo false": {
host: "123hello.dkr.ecr.foo.amazonaws.comfoo",
expIs: false,
},
"public.ecr.aws should be true": {
host: "public.ecr.aws",
expIs: true,
},
"public.ecr.aws with random subdomains 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 TestRepoImage(t *testing.T) {
tests := map[string]struct {
path string
expRepo, expImage string
}{
"single image should return as image": {
path: "kube-scheduler",
expRepo: "",
expImage: "kube-scheduler",
},
"two segments to path should return both": {
path: "jetstack-cre/version-checker",
expRepo: "jetstack-cre",
expImage: "version-checker",
},
"multiple segments to path should return all in repo, last segment image": {
path: "k8s-artifacts-prod/ingress-nginx/nginx",
expRepo: "k8s-artifacts-prod/ingress-nginx",
expImage: "nginx",
},
"region": {
path: "000000000000.dkr.ecr.eu-west-2.amazonaws.com/version-checker",
expRepo: "000000000000.dkr.ecr.eu-west-2.amazonaws.com",
expImage: "version-checker",
},
}
handler := new(Client)
for name, test := range tests {
t.Run(name, func(t *testing.T) {
repo, image := handler.RepoImageFromPath(test.path)
assert.Equal(t, repo, test.expRepo)
assert.Equal(t, image, test.expImage)
})
}
}