|
|
|
@ -26,29 +26,94 @@ import (
|
|
|
|
|
// full/path/to/file.oci[.aci]
|
|
|
|
|
|
|
|
|
|
func TestReference_Parse(t *testing.T) { |
|
|
|
|
d1 := "docker://ubuntu" |
|
|
|
|
d2 := "docker://registry.wegmueller.it/ubuntu" |
|
|
|
|
d3 := "docker:ubuntu" |
|
|
|
|
d4 := "docker:toast/redis:mytag" |
|
|
|
|
r := NewReferenceString(d1) |
|
|
|
|
assert.Equal(t, "ubuntu", r.Name) |
|
|
|
|
r = NewReferenceString(d2) |
|
|
|
|
assert.Equal(t, "registry.wegmueller.it", r.Host) |
|
|
|
|
assert.Equal(t, "ubuntu", r.Name) |
|
|
|
|
r = NewReferenceString(d3) |
|
|
|
|
assert.Equal(t, "ubuntu", r.Name) |
|
|
|
|
r = NewReferenceString(d4) |
|
|
|
|
assert.Equal(t, "toast", r.Repository) |
|
|
|
|
assert.Equal(t, "redis", r.Name) |
|
|
|
|
assert.Equal(t, "mytag", r.Tag) |
|
|
|
|
o1 := "oci:/full/path/to/directory" |
|
|
|
|
o2 := "oci:/full/path/to/file" |
|
|
|
|
r = NewReferenceString(o1) |
|
|
|
|
assert.Equal(t, "/full/path/to/directory", r.Path) |
|
|
|
|
r = NewReferenceString(o2) |
|
|
|
|
assert.Equal(t, "/full/path/to/file", r.Path) |
|
|
|
|
f2 := "full/path/to/file.oci" |
|
|
|
|
r = NewReferenceString(f2) |
|
|
|
|
assert.Equal(t, "full/path/to/file.oci", r.Path) |
|
|
|
|
assert.Equal(t, SchemeOCIArchive, r.Scheme) |
|
|
|
|
type Expected struct { |
|
|
|
|
name string |
|
|
|
|
repository string |
|
|
|
|
tag string |
|
|
|
|
host string |
|
|
|
|
path string |
|
|
|
|
scheme string |
|
|
|
|
} |
|
|
|
|
testCases := []struct { |
|
|
|
|
expected Expected |
|
|
|
|
input string |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
name: "ubuntu", |
|
|
|
|
repository: "library", |
|
|
|
|
tag: "latest", |
|
|
|
|
host: "", |
|
|
|
|
}, |
|
|
|
|
input: "docker://ubuntu", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
name: "ubuntu", |
|
|
|
|
repository: "library", |
|
|
|
|
tag: "latest", |
|
|
|
|
host: "registry.wegmueller.it", |
|
|
|
|
}, |
|
|
|
|
input: "docker://registry.wegmueller.it/ubuntu", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
name: "ubuntu", |
|
|
|
|
repository: "library", |
|
|
|
|
tag: "latest", |
|
|
|
|
host: "", |
|
|
|
|
}, |
|
|
|
|
input: "docker:ubuntu", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
name: "redis", |
|
|
|
|
repository: "toast", |
|
|
|
|
tag: "mytag", |
|
|
|
|
host: "", |
|
|
|
|
}, |
|
|
|
|
input: "docker:toast/redis:mytag", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
scheme: SchemeOCIDirectory, |
|
|
|
|
path: "/full/path/to/directory", |
|
|
|
|
}, |
|
|
|
|
input: "oci:/full/path/to/directory", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
scheme: SchemeOCIArchive, |
|
|
|
|
path: "/full/path/to/file.tar", |
|
|
|
|
}, |
|
|
|
|
input: "oci:/full/path/to/file.tar", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
expected: Expected{ |
|
|
|
|
repository: "openindiana", |
|
|
|
|
name: "hipster", |
|
|
|
|
tag: "latest", |
|
|
|
|
}, |
|
|
|
|
input: "openindiana/hipster:latest", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for i, tc := range testCases { |
|
|
|
|
r := NewReferenceString(tc.input) |
|
|
|
|
switch r.Scheme { |
|
|
|
|
case SchemeDocker: |
|
|
|
|
assert.Equal(t, tc.expected.repository, r.Repository) |
|
|
|
|
assert.Equal(t, tc.expected.name, r.Name) |
|
|
|
|
assert.Equal(t, tc.expected.host, r.Host) |
|
|
|
|
assert.Equal(t, tc.expected.tag, r.Tag) |
|
|
|
|
if t.Failed() { |
|
|
|
|
t.Fatalf("testcase %d failed with input %s:", i, tc.input) |
|
|
|
|
} |
|
|
|
|
case SchemeOCIArchive, SchemeOCIDirectory: |
|
|
|
|
assert.Equal(t, tc.expected.path, r.Path) |
|
|
|
|
default: |
|
|
|
|
t.Fatalf("schema %s not supported by testcases yet: testcase %d: %s", r.Scheme, i, tc.input) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|