mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-22 06:47:00 +00:00
Apply code review recommendations
This commit is contained in:
@@ -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 <image>:<newtag> or <image>@<digest>")
|
||||
}
|
||||
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
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user