summaryrefslogtreecommitdiff
path: root/libpod/image/parts_test.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2019-01-09 20:32:30 +0100
committerMiloslav Trmač <mitr@redhat.com>2019-01-14 04:07:23 +0100
commit72777b7fee22e04edee08034927d5864ffc4bc3e (patch)
tree86f2794d67f79df140acdc0d1cd122ed77030ae0 /libpod/image/parts_test.go
parentae2a95196e9e5a3519b396105d01a3661de330ba (diff)
downloadpodman-72777b7fee22e04edee08034927d5864ffc4bc3e.tar.gz
podman-72777b7fee22e04edee08034927d5864ffc4bc3e.tar.bz2
podman-72777b7fee22e04edee08034927d5864ffc4bc3e.zip
Add imageParts.referenceWithRegistry
This is the primary goal of decompose()+assemble(), to support qualifying an image name. Does not have any users yet, so does 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.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/libpod/image/parts_test.go b/libpod/image/parts_test.go
index 733e8e855..b2cc0f8c0 100644
--- a/libpod/image/parts_test.go
+++ b/libpod/image/parts_test.go
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestDecompose(t *testing.T) {
@@ -62,3 +63,44 @@ func TestDecompose(t *testing.T) {
}
}
}
+
+func TestImagePartsReferenceWithRegistry(t *testing.T) {
+ const digestSuffix = "@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+
+ for _, c := range []struct {
+ input string
+ withDocker, withNonDocker string
+ }{
+ {"example.com/ns/busybox", "", ""}, // Fully-qualified input is invalid.
+ {"busybox", "docker.io/library/busybox", "example.com/busybox"}, // Single-name input
+ {"ns/busybox", "docker.io/ns/busybox", "example.com/ns/busybox"}, // Namespaced input
+ {"ns/busybox:notlatest", "docker.io/ns/busybox:notlatest", "example.com/ns/busybox:notlatest"}, // name:tag
+ {"ns/busybox" + digestSuffix, "docker.io/ns/busybox" + digestSuffix, "example.com/ns/busybox" + digestSuffix}, // name@digest
+ { // name:tag@digest
+ "ns/busybox:notlatest" + digestSuffix,
+ "docker.io/ns/busybox:notlatest" + digestSuffix, "example.com/ns/busybox:notlatest" + digestSuffix,
+ },
+ } {
+ parts, err := decompose(c.input)
+ require.NoError(t, err)
+ if c.withDocker == "" {
+ _, err := parts.referenceWithRegistry("docker.io")
+ assert.Error(t, err, c.input)
+ _, err = parts.referenceWithRegistry("example.com")
+ assert.Error(t, err, c.input)
+ } else {
+ ref, err := parts.referenceWithRegistry("docker.io")
+ require.NoError(t, err, c.input)
+ assert.Equal(t, c.withDocker, ref.String())
+ ref, err = parts.referenceWithRegistry("example.com")
+ require.NoError(t, err, c.input)
+ assert.Equal(t, c.withNonDocker, ref.String())
+ }
+ }
+
+ // Invalid registry value
+ parts, err := decompose("busybox")
+ require.NoError(t, err)
+ _, err = parts.referenceWithRegistry("invalid@domain")
+ assert.Error(t, err)
+}