summaryrefslogtreecommitdiff
path: root/libpod/image/parts_test.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-18 22:29:35 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-23 12:44:38 +0000
commite8bc9141343714cd0266daafbcb6eaf121aaab3b (patch)
treecbbbf438e8db5939e233410a94f375efbd2f3d6b /libpod/image/parts_test.go
parenteb17182ecf3a4cdd55b87b7809791833200fcb2b (diff)
downloadpodman-e8bc9141343714cd0266daafbcb6eaf121aaab3b.tar.gz
podman-e8bc9141343714cd0266daafbcb6eaf121aaab3b.tar.bz2
podman-e8bc9141343714cd0266daafbcb6eaf121aaab3b.zip
Add unit tests for imageParts
Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1112 Approved by: rhatdan
Diffstat (limited to 'libpod/image/parts_test.go')
-rw-r--r--libpod/image/parts_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/libpod/image/parts_test.go b/libpod/image/parts_test.go
new file mode 100644
index 000000000..eba938cc2
--- /dev/null
+++ b/libpod/image/parts_test.go
@@ -0,0 +1,69 @@
+package image
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestDecompose(t *testing.T) {
+ const digestSuffix = "@sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+
+ for _, c := range []struct {
+ input string
+ transport, registry, name, tag string
+ isTagged, hasRegistry bool
+ assembled string
+ assembledWithTransport string
+ }{
+ {"#", "", "", "", "", false, false, "", ""}, // Entirely invalid input
+ { // Fully qualified docker.io, name-only input
+ "docker.io/library/busybox", "docker://", "docker.io", "library/busybox", "latest", false, true,
+ "docker.io/library/busybox:latest", "docker://docker.io/library/busybox:latest",
+ },
+ { // Fully qualified example.com, name-only input
+ "example.com/ns/busybox", "docker://", "example.com", "ns/busybox", "latest", false, true,
+ "example.com/ns/busybox:latest", "docker://example.com/ns/busybox:latest",
+ },
+ { // Unqualified single-name input
+ "busybox", "docker://", "", "busybox", "latest", false, false,
+ // FIXME? The [empty]/busybox syntax is surprising.
+ "/busybox:latest", "docker:///busybox:latest",
+ },
+ { // Unqualified namespaced input
+ // FIXME: .registry == "ns" !!
+ "ns/busybox", "docker://", "ns", "busybox", "latest", false, true,
+ "ns/busybox:latest", "docker://ns/busybox:latest",
+ },
+ { // name:tag
+ "example.com/ns/busybox:notlatest", "docker://", "example.com", "ns/busybox", "notlatest", true, true,
+ "example.com/ns/busybox:notlatest", "docker://example.com/ns/busybox:notlatest",
+ },
+ { // name@digest
+ // FIXME? .tag == "none"
+ "example.com/ns/busybox" + digestSuffix, "docker://", "example.com", "ns/busybox", "none", false, true,
+ // FIXME: this drops the digest and replaces it with an incorrect tag.
+ "example.com/ns/busybox:none", "docker://example.com/ns/busybox:none",
+ },
+ { // name:tag@digest
+ "example.com/ns/busybox:notlatest" + digestSuffix, "docker://", "example.com", "ns/busybox", "notlatest", true, true,
+ // FIXME: This drops the digest
+ "example.com/ns/busybox:notlatest", "docker://example.com/ns/busybox:notlatest",
+ },
+ } {
+ parts, err := decompose(c.input)
+ if c.transport == "" {
+ assert.Error(t, err, c.input)
+ } else {
+ assert.NoError(t, err, c.input)
+ assert.Equal(t, c.transport, parts.transport, c.input)
+ assert.Equal(t, c.registry, parts.registry, c.input)
+ assert.Equal(t, c.name, parts.name, c.input)
+ assert.Equal(t, c.tag, parts.tag, c.input)
+ assert.Equal(t, c.isTagged, parts.isTagged, c.input)
+ assert.Equal(t, c.hasRegistry, parts.hasRegistry, c.input)
+ assert.Equal(t, c.assembled, parts.assemble(), c.input)
+ assert.Equal(t, c.assembledWithTransport, parts.assembleWithTransport(), c.input)
+ }
+ }
+}