summaryrefslogtreecommitdiff
path: root/libpod/image/image_test.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_test.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_test.go')
-rw-r--r--libpod/image/image_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go
index 04877dbe5..2236b2010 100644
--- a/libpod/image/image_test.go
+++ b/libpod/image/image_test.go
@@ -198,3 +198,25 @@ func Test_stripSha256(t *testing.T) {
assert.Equal(t, stripSha256("sha256:"), "sha256:")
assert.Equal(t, stripSha256("sha256:a"), "a")
}
+
+func TestNormalizeTag(t *testing.T) {
+ const digestSuffix = "@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+
+ for _, c := range []struct{ input, expected string }{
+ {"#", ""}, // Clearly invalid
+ {"example.com/busybox", "example.com/busybox:latest"}, // Qualified name-only
+ {"example.com/busybox:notlatest", "example.com/busybox:notlatest"}, // Qualified name:tag
+ {"example.com/busybox" + digestSuffix, "example.com/busybox" + digestSuffix + ":none"}, // Qualified name@digest; FIXME: The result is not even syntactically valid!
+ {"example.com/busybox:notlatest" + digestSuffix, "example.com/busybox:notlatest" + digestSuffix}, // Qualified name:tag@digest
+ {"busybox:latest", "localhost/busybox:latest"}, // Unqualified name-only
+ {"ns/busybox:latest", "ns/busybox:latest"}, // Unqualified with a dot-less namespace FIXME: "ns" is treated as a registry
+ } {
+ res, err := normalizeTag(c.input)
+ if c.expected == "" {
+ assert.Error(t, err, c.input)
+ } else {
+ assert.NoError(t, err, c.input)
+ assert.Equal(t, c.expected, res)
+ }
+ }
+}