Apply code review recommendations

This commit is contained in:
Alexandr Burdiyan
2018-09-10 11:48:47 +02:00
parent 5401bd367b
commit 6dbf4b5b60
2 changed files with 11 additions and 12 deletions

View File

@@ -72,28 +72,27 @@ and overwrite the previous ones if the image tag exists.
// Validate validates setImageTag command. // Validate validates setImageTag command.
func (o *setImageTagOptions) Validate(args []string) error { func (o *setImageTagOptions) Validate(args []string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("no image and newTag specified") return errors.New("no image specified")
} }
o.imageTagMap = make(map[string]types.ImageTag) o.imageTagMap = make(map[string]types.ImageTag)
for _, arg := range args { for _, arg := range args {
if strings.Contains(arg, "@") { if s := strings.Split(arg, "@"); len(s) > 1 {
img := strings.Split(arg, "@") o.imageTagMap[s[0]] = types.ImageTag{
o.imageTagMap[img[0]] = types.ImageTag{ Name: s[0],
Name: img[0], Digest: s[1],
Digest: img[1],
} }
continue continue
} }
imagetag := pattern.FindStringSubmatch(arg) s := pattern.FindStringSubmatch(arg)
if len(imagetag) != 3 { if len(s) != 3 {
return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>") return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>")
} }
o.imageTagMap[imagetag[1]] = types.ImageTag{ o.imageTagMap[s[1]] = types.ImageTag{
Name: imagetag[1], Name: s[1],
NewTag: imagetag[2], NewTag: s[2],
} }
} }
return nil return nil

View File

@@ -96,7 +96,7 @@ func TestSetImageTagsNoArgs(t *testing.T) {
if err == nil { if err == nil {
t.Errorf("expected error: %v", err) t.Errorf("expected error: %v", err)
} }
if err.Error() != "no image and newTag specified" { if err.Error() != "no image specified" {
t.Errorf("incorrect error: %v", err.Error()) t.Errorf("incorrect error: %v", err.Error())
} }
} }