summaryrefslogtreecommitdiff
path: root/libpod/image/parts_test.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2019-01-09 21:33:01 +0100
committerMiloslav Trmač <mitr@redhat.com>2019-01-14 04:07:23 +0100
commit1c19d19c6ef9627413e34b30a643bef9b2970acb (patch)
treec2b7c6400a9a12b7e0469370a050cfa4d82b8053 /libpod/image/parts_test.go
parente58aa74766c14844700330e11e8f0b48843884be (diff)
downloadpodman-1c19d19c6ef9627413e34b30a643bef9b2970acb.tar.gz
podman-1c19d19c6ef9627413e34b30a643bef9b2970acb.tar.bz2
podman-1c19d19c6ef9627413e34b30a643bef9b2970acb.zip
Add imageParts.normalizedReference()
This will be used in normalizeTag to work with references instead of strings. Not used anywhere yet, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'libpod/image/parts_test.go')
-rw-r--r--libpod/image/parts_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/image/parts_test.go b/libpod/image/parts_test.go
index 3ca39b1dc..9955a20ea 100644
--- a/libpod/image/parts_test.go
+++ b/libpod/image/parts_test.go
@@ -93,3 +93,31 @@ func TestImagePartsReferenceWithRegistry(t *testing.T) {
_, err = parts.referenceWithRegistry("invalid@domain")
assert.Error(t, err)
}
+
+func TestImagePartsNormalizedReference(t *testing.T) {
+ const digestSuffix = "@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+
+ for _, c := range []struct{ input, expected string }{
+ {"busybox", ""}, // Unqualified input is invalid
+ {"docker.io/busybox", "docker.io/library/busybox"}, // docker.io single-name
+ {"example.com/busybox", "example.com/busybox"}, // example.com single-name
+ {"docker.io/ns/busybox", "docker.io/ns/busybox"}, // docker.io namespaced
+ {"example.com/ns/busybox", "example.com/ns/busybox"}, // example.com namespaced
+ {"example.com/ns/busybox:notlatest", "example.com/ns/busybox:notlatest"}, // name:tag
+ {"example.com/ns/busybox" + digestSuffix, "example.com/ns/busybox" + digestSuffix}, // name@digest
+ { // name:tag@digest
+ "example.com/ns/busybox:notlatest" + digestSuffix, "example.com/ns/busybox:notlatest" + digestSuffix,
+ },
+ } {
+ parts, err := decompose(c.input)
+ require.NoError(t, err)
+ if c.expected == "" {
+ _, err := parts.normalizedReference()
+ assert.Error(t, err, c.input)
+ } else {
+ ref, err := parts.normalizedReference()
+ require.NoError(t, err, c.input)
+ assert.Equal(t, c.expected, ref.String())
+ }
+ }
+}