Skip to content

Commit 1211b10

Browse files
committed
add ecr test
1 parent e9e2777 commit 1211b10

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

extractor/docker/token/ecr/ecr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func getSession(option types.DockerOption) (*session.Session, error) {
4646

4747
func (e *ECR) CheckOptions(domain string, option types.DockerOption) error {
4848
if !strings.HasSuffix(domain, ecrURL) {
49-
return xerrors.New("invalid ECR url pattern")
49+
return xerrors.Errorf("ECR : %w", types.InvalidURLPattern)
5050
}
5151
sess := session.Must(getSession(option))
5252
svc := ecr.New(sess)

extractor/docker/token/ecr/ecr_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,45 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/knqyf263/fanal/types"
8+
"golang.org/x/xerrors"
9+
710
"github.com/aws/aws-sdk-go/aws/request"
811

912
"github.com/aws/aws-sdk-go/aws"
1013
"github.com/aws/aws-sdk-go/service/ecr"
1114
"github.com/aws/aws-sdk-go/service/ecr/ecriface"
1215
)
1316

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]\nexpected error based on %v\nactual : %v", testname, v.wantErr, err)
40+
}
41+
continue
42+
}
43+
}
44+
}
45+
1446
type mockedECR struct {
1547
ecriface.ECRAPI
1648
Resp ecr.GetAuthorizationTokenOutput

extractor/docker/token/gcr/gcr_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestCheckOptions(t *testing.T) {
3636
}
3737

3838
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)
4141
if v.wantErr != nil {
4242
if err == nil {
4343
t.Errorf("%s : expected error but no error", testname)
@@ -48,8 +48,8 @@ func TestCheckOptions(t *testing.T) {
4848
}
4949
continue
5050
}
51-
if !reflect.DeepEqual(v.gcr, a) {
52-
t.Errorf("[%s]\nexpected : %v\nactual : %v", testname, v.gcr, a)
51+
if !reflect.DeepEqual(v.gcr, g) {
52+
t.Errorf("[%s]\nexpected : %v\nactual : %v", testname, v.gcr, g)
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)