File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ func getSession(option types.DockerOption) (*session.Session, error) {
46
46
47
47
func (e * ECR ) CheckOptions (domain string , option types.DockerOption ) error {
48
48
if ! strings .HasSuffix (domain , ecrURL ) {
49
- return xerrors .New ( "invalid ECR url pattern" )
49
+ return xerrors .Errorf ( " ECR : %w" , types . InvalidURLPattern )
50
50
}
51
51
sess := session .Must (getSession (option ))
52
52
svc := ecr .New (sess )
Original file line number Diff line number Diff line change @@ -4,13 +4,45 @@ import (
4
4
"context"
5
5
"testing"
6
6
7
+ "github.com/knqyf263/fanal/types"
8
+ "golang.org/x/xerrors"
9
+
7
10
"github.com/aws/aws-sdk-go/aws/request"
8
11
9
12
"github.com/aws/aws-sdk-go/aws"
10
13
"github.com/aws/aws-sdk-go/service/ecr"
11
14
"github.com/aws/aws-sdk-go/service/ecr/ecriface"
12
15
)
13
16
17
+ func TestCheckOptions (t * testing.T ) {
18
+ var tests = map [string ]struct {
19
+ domain string
20
+ opt types.DockerOption
21
+ wantErr error
22
+ }{
23
+ "InvalidURL" : {
24
+ domain : "alpine:3.9" ,
25
+ opt : types.DockerOption {},
26
+ wantErr : types .InvalidURLPattern ,
27
+ },
28
+ "NoOption" : {
29
+ domain : "xxx.ecr.ap-northeast-1.amazonaws.com" ,
30
+ opt : types.DockerOption {},
31
+ },
32
+ }
33
+
34
+ for testname , v := range tests {
35
+ a := & ECR {}
36
+ err := a .CheckOptions (v .domain , v .opt )
37
+ if err != nil {
38
+ if ! xerrors .Is (err , v .wantErr ) {
39
+ t .Errorf ("[%s]\n expected error based on %v\n actual : %v" , testname , v .wantErr , err )
40
+ }
41
+ continue
42
+ }
43
+ }
44
+ }
45
+
14
46
type mockedECR struct {
15
47
ecriface.ECRAPI
16
48
Resp ecr.GetAuthorizationTokenOutput
Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ func TestCheckOptions(t *testing.T) {
36
36
}
37
37
38
38
for testname , v := range tests {
39
- a := & GCR {}
40
- err := a .CheckOptions (v .domain , v .opt )
39
+ g := & GCR {}
40
+ err := g .CheckOptions (v .domain , v .opt )
41
41
if v .wantErr != nil {
42
42
if err == nil {
43
43
t .Errorf ("%s : expected error but no error" , testname )
@@ -48,8 +48,8 @@ func TestCheckOptions(t *testing.T) {
48
48
}
49
49
continue
50
50
}
51
- if ! reflect .DeepEqual (v .gcr , a ) {
52
- t .Errorf ("[%s]\n expected : %v\n actual : %v" , testname , v .gcr , a )
51
+ if ! reflect .DeepEqual (v .gcr , g ) {
52
+ t .Errorf ("[%s]\n expected : %v\n actual : %v" , testname , v .gcr , g )
53
53
}
54
54
}
55
55
}
You can’t perform that action at this time.
0 commit comments