From 6dbf4b5b60b06f25dce2b665593f3f0014aa8764 Mon Sep 17 00:00:00 2001 From: Alexandr Burdiyan Date: Mon, 10 Sep 2018 11:48:47 +0200 Subject: [PATCH] Apply code review recommendations --- pkg/commands/setimagetag.go | 21 ++++++++++----------- pkg/commands/setimagetag_test.go | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/commands/setimagetag.go b/pkg/commands/setimagetag.go index a0caa70f9..f6d82c3b3 100644 --- a/pkg/commands/setimagetag.go +++ b/pkg/commands/setimagetag.go @@ -72,28 +72,27 @@ and overwrite the previous ones if the image tag exists. // Validate validates setImageTag command. func (o *setImageTagOptions) Validate(args []string) error { 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) for _, arg := range args { - if strings.Contains(arg, "@") { - img := strings.Split(arg, "@") - o.imageTagMap[img[0]] = types.ImageTag{ - Name: img[0], - Digest: img[1], + if s := strings.Split(arg, "@"); len(s) > 1 { + o.imageTagMap[s[0]] = types.ImageTag{ + Name: s[0], + Digest: s[1], } continue } - imagetag := pattern.FindStringSubmatch(arg) - if len(imagetag) != 3 { + s := pattern.FindStringSubmatch(arg) + if len(s) != 3 { return errors.New("invalid format of imagetag, must specify it as : or @") } - o.imageTagMap[imagetag[1]] = types.ImageTag{ - Name: imagetag[1], - NewTag: imagetag[2], + o.imageTagMap[s[1]] = types.ImageTag{ + Name: s[1], + NewTag: s[2], } } return nil diff --git a/pkg/commands/setimagetag_test.go b/pkg/commands/setimagetag_test.go index c5bf0d313..9d23a1117 100644 --- a/pkg/commands/setimagetag_test.go +++ b/pkg/commands/setimagetag_test.go @@ -96,7 +96,7 @@ func TestSetImageTagsNoArgs(t *testing.T) { if err == nil { 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()) } }