-
Notifications
You must be signed in to change notification settings - Fork 11
/
auth_test.go
65 lines (60 loc) · 1.45 KB
/
auth_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
package main
import (
"testing"
"gotest.tools/assert"
)
func TestECRRegionExtract(t *testing.T) {
tests := []struct {
registry string
wantRegion string
wantOK bool
wantErr string
}{
{
registry: "012345678901.dkr.ecr.us-east-1.amazonaws.com",
wantRegion: "us-east-1",
wantOK: true,
},
{
registry: "210987654321.dkr.ecr.cn-north-1.amazonaws.com.cn",
wantRegion: "cn-north-1",
wantOK: true,
},
{
registry: "123456789012.dkr.ecr-fips.us-gov-west-1.amazonaws.com",
wantRegion: "us-gov-west-1",
wantOK: true,
},
{
registry: "public.ecr.aws",
wantRegion: "",
wantOK: true,
},
{
registry: "gcr.io",
wantOK: false,
wantErr: "kyverno-notation-aws plugin can only be used with Amazon Elastic Container Registry",
},
{
registry: "not.ecr.io",
wantOK: false,
wantErr: "kyverno-notation-aws plugin can only be used with Amazon Elastic Container Registry",
},
{
registry: "public.ecr.aws.fake.example.com",
wantOK: false,
wantErr: "kyverno-notation-aws plugin can only be used with Amazon Elastic Container Registry",
},
}
for _, tt := range tests {
t.Run(tt.registry, func(t *testing.T) {
region, err := getRegion(tt.registry)
if tt.wantOK {
assert.NilError(t, err, "unexpected error")
} else {
assert.Error(t, err, tt.wantErr, "unexpected OK")
}
assert.Equal(t, region, tt.wantRegion, "unexpected region")
})
}
}