summaryrefslogtreecommitdiff
path: root/libpod/image/image.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-18 22:50:53 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-23 12:44:38 +0000
commit70589c326c2da7616ff0c4def8792130543ff383 (patch)
tree1f2f19610d76182e9c04872f9e817a6b62873fc1 /libpod/image/image.go
parent501acd460ef0acd5c4ab8d935efc1696916d23fe (diff)
downloadpodman-70589c326c2da7616ff0c4def8792130543ff383.tar.gz
podman-70589c326c2da7616ff0c4def8792130543ff383.tar.bz2
podman-70589c326c2da7616ff0c4def8792130543ff383.zip
Split normalizeTag from Image.TagImage
... so that it can be tested without side effects, and add the tests. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1112 Approved by: rhatdan
Diffstat (limited to 'libpod/image/image.go')
-rw-r--r--libpod/image/image.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 3863338b5..7ea851f5d 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -457,12 +457,11 @@ func getImageDigest(ctx context.Context, src types.ImageReference, sc *types.Sys
return "@" + digest.Hex(), nil
}
-// TagImage adds a tag to the given image
-func (i *Image) TagImage(tag string) error {
- i.reloadImage()
+// normalizeTag returns the canonical version of tag for use in Image.Names()
+func normalizeTag(tag string) (string, error) {
decomposedTag, err := decompose(tag)
if err != nil {
- return err
+ return "", err
}
// If the input does not have a tag, we need to add one (latest)
if !decomposedTag.isTagged {
@@ -472,6 +471,16 @@ func (i *Image) TagImage(tag string) error {
if !decomposedTag.hasRegistry {
tag = fmt.Sprintf("%s/%s", DefaultLocalRepo, tag)
}
+ return tag, nil
+}
+
+// TagImage adds a tag to the given image
+func (i *Image) TagImage(tag string) error {
+ i.reloadImage()
+ tag, err := normalizeTag(tag)
+ if err != nil {
+ return err
+ }
tags := i.Names()
if util.StringInSlice(tag, tags) {
return nil