|
@@ -6,7 +6,7 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
-var testPaths = map[string]Path{
|
|
|
+var testNames = map[string]Name{
|
|
|
"mistral:latest": {name: "mistral", tag: "latest"},
|
|
|
"mistral": {name: "mistral"},
|
|
|
"mistral:30B": {name: "mistral", tag: "30B"},
|
|
@@ -36,33 +36,33 @@ var testPaths = map[string]Path{
|
|
|
"file:///etc/passwd:latest": {},
|
|
|
"file:///etc/passwd:latest+u": {},
|
|
|
|
|
|
- strings.Repeat("a", MaxPathLength): {name: strings.Repeat("a", MaxPathLength)},
|
|
|
- strings.Repeat("a", MaxPathLength+1): {},
|
|
|
+ strings.Repeat("a", MaxNameLength): {name: strings.Repeat("a", MaxNameLength)},
|
|
|
+ strings.Repeat("a", MaxNameLength+1): {},
|
|
|
}
|
|
|
|
|
|
-func TestPathParts(t *testing.T) {
|
|
|
+func TestNameParts(t *testing.T) {
|
|
|
const wantNumParts = 5
|
|
|
- var p Path
|
|
|
+ var p Name
|
|
|
if len(p.Parts()) != wantNumParts {
|
|
|
t.Errorf("Parts() = %d; want %d", len(p.Parts()), wantNumParts)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestParsePath(t *testing.T) {
|
|
|
- for s, want := range testPaths {
|
|
|
+func TestParseName(t *testing.T) {
|
|
|
+ for s, want := range testNames {
|
|
|
for _, prefix := range []string{"", "https://", "http://"} {
|
|
|
// We should get the same results with or without the
|
|
|
// http(s) prefixes
|
|
|
s := prefix + s
|
|
|
|
|
|
t.Run(s, func(t *testing.T) {
|
|
|
- got := ParsePath(s)
|
|
|
+ got := ParseName(s)
|
|
|
if got != want {
|
|
|
- t.Errorf("ParsePath(%q) = %q; want %q", s, got, want)
|
|
|
+ t.Errorf("ParseName(%q) = %q; want %q", s, got, want)
|
|
|
}
|
|
|
|
|
|
// test round-trip
|
|
|
- if ParsePath(got.String()) != got {
|
|
|
+ if ParseName(got.String()) != got {
|
|
|
t.Errorf("String() = %s; want %s", got.String(), s)
|
|
|
}
|
|
|
|
|
@@ -76,7 +76,7 @@ func TestParsePath(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestPathComplete(t *testing.T) {
|
|
|
+func TestName(t *testing.T) {
|
|
|
cases := []struct {
|
|
|
in string
|
|
|
complete bool
|
|
@@ -92,8 +92,8 @@ func TestPathComplete(t *testing.T) {
|
|
|
|
|
|
for _, tt := range cases {
|
|
|
t.Run(tt.in, func(t *testing.T) {
|
|
|
- p := ParsePath(tt.in)
|
|
|
- t.Logf("ParsePath(%q) = %#v", tt.in, p)
|
|
|
+ p := ParseName(tt.in)
|
|
|
+ t.Logf("ParseName(%q) = %#v", tt.in, p)
|
|
|
if g := p.Complete(); g != tt.complete {
|
|
|
t.Errorf("Complete(%q) = %v; want %v", tt.in, g, tt.complete)
|
|
|
}
|
|
@@ -104,7 +104,7 @@ func TestPathComplete(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestPathStringVariants(t *testing.T) {
|
|
|
+func TestNameStringVariants(t *testing.T) {
|
|
|
cases := []struct {
|
|
|
in string
|
|
|
nameAndTag string
|
|
@@ -116,19 +116,19 @@ func TestPathStringVariants(t *testing.T) {
|
|
|
|
|
|
for _, tt := range cases {
|
|
|
t.Run(tt.in, func(t *testing.T) {
|
|
|
- p := ParsePath(tt.in)
|
|
|
- t.Logf("ParsePath(%q) = %#v", tt.in, p)
|
|
|
- if g := p.NameAndTag(); g != tt.nameAndTag {
|
|
|
- t.Errorf("NameAndTag(%q) = %q; want %q", tt.in, g, tt.nameAndTag)
|
|
|
+ p := ParseName(tt.in)
|
|
|
+ t.Logf("ParseName(%q) = %#v", tt.in, p)
|
|
|
+ if g := p.ShortAndTag(); g != tt.nameAndTag {
|
|
|
+ t.Errorf("ShortAndTag(%q) = %q; want %q", tt.in, g, tt.nameAndTag)
|
|
|
}
|
|
|
- if g := p.NameTagAndBuild(); g != tt.nameTagAndBuild {
|
|
|
- t.Errorf("NameTagAndBuild(%q) = %q; want %q", tt.in, g, tt.nameTagAndBuild)
|
|
|
+ if g := p.ShortTagAndBuild(); g != tt.nameTagAndBuild {
|
|
|
+ t.Errorf("ShortTagAndBuild(%q) = %q; want %q", tt.in, g, tt.nameTagAndBuild)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestPathFull(t *testing.T) {
|
|
|
+func TestNameFull(t *testing.T) {
|
|
|
const empty = "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/!(MISSING NAME):!(MISSING TAG)+!(MISSING BUILD)"
|
|
|
|
|
|
cases := []struct {
|
|
@@ -151,8 +151,8 @@ func TestPathFull(t *testing.T) {
|
|
|
|
|
|
for _, tt := range cases {
|
|
|
t.Run(tt.in, func(t *testing.T) {
|
|
|
- p := ParsePath(tt.in)
|
|
|
- t.Logf("ParsePath(%q) = %#v", tt.in, p)
|
|
|
+ p := ParseName(tt.in)
|
|
|
+ t.Logf("ParseName(%q) = %#v", tt.in, p)
|
|
|
if g := p.Full(); g != tt.wantFull {
|
|
|
t.Errorf("Full(%q) = %q; want %q", tt.in, g, tt.wantFull)
|
|
|
}
|
|
@@ -160,44 +160,44 @@ func TestPathFull(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestParsePathAllocs(t *testing.T) {
|
|
|
+func TestParseNameAllocs(t *testing.T) {
|
|
|
// test allocations
|
|
|
- var r Path
|
|
|
+ var r Name
|
|
|
allocs := testing.AllocsPerRun(1000, func() {
|
|
|
- r = ParsePath("example.com/mistral:7b+Q4_0")
|
|
|
+ r = ParseName("example.com/mistral:7b+Q4_0")
|
|
|
})
|
|
|
_ = r
|
|
|
if allocs > 0 {
|
|
|
- t.Errorf("ParsePath allocs = %v; want 0", allocs)
|
|
|
+ t.Errorf("ParseName allocs = %v; want 0", allocs)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func BenchmarkParsePath(b *testing.B) {
|
|
|
+func BenchmarkParseName(b *testing.B) {
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
- var r Path
|
|
|
+ var r Name
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
- r = ParsePath("example.com/mistral:7b+Q4_0")
|
|
|
+ r = ParseName("example.com/mistral:7b+Q4_0")
|
|
|
}
|
|
|
_ = r
|
|
|
}
|
|
|
|
|
|
-func FuzzParsePath(f *testing.F) {
|
|
|
+func FuzzParseName(f *testing.F) {
|
|
|
f.Add("example.com/mistral:7b+Q4_0")
|
|
|
f.Add("example.com/mistral:7b+q4_0")
|
|
|
f.Add("example.com/mistral:7b+x")
|
|
|
f.Add("x/y/z:8n+I")
|
|
|
f.Fuzz(func(t *testing.T, s string) {
|
|
|
- r0 := ParsePath(s)
|
|
|
+ r0 := ParseName(s)
|
|
|
if !r0.Valid() {
|
|
|
- if r0 != (Path{}) {
|
|
|
+ if r0 != (Name{}) {
|
|
|
t.Errorf("expected invalid path to be zero value; got %#v", r0)
|
|
|
}
|
|
|
t.Skipf("invalid path: %q", s)
|
|
|
}
|
|
|
|
|
|
for _, p := range r0.Parts() {
|
|
|
- if len(p) > MaxPathLength {
|
|
|
+ if len(p) > MaxNameLength {
|
|
|
t.Errorf("part too long: %q", p)
|
|
|
}
|
|
|
}
|
|
@@ -206,7 +206,7 @@ func FuzzParsePath(f *testing.F) {
|
|
|
t.Errorf("String() did not round-trip with case insensitivity: %q\ngot = %q\nwant = %q", s, r0.String(), s)
|
|
|
}
|
|
|
|
|
|
- r1 := ParsePath(r0.String())
|
|
|
+ r1 := ParseName(r0.String())
|
|
|
if r0 != r1 {
|
|
|
t.Errorf("round-trip mismatch: %+v != %+v", r0, r1)
|
|
|
}
|
|
@@ -216,8 +216,8 @@ func FuzzParsePath(f *testing.F) {
|
|
|
|
|
|
func ExampleMerge() {
|
|
|
r := Merge(
|
|
|
- ParsePath("mistral"),
|
|
|
- ParsePath("registry.ollama.com/XXXXX:latest+Q4_0"),
|
|
|
+ ParseName("mistral"),
|
|
|
+ ParseName("registry.ollama.com/XXXXX:latest+Q4_0"),
|
|
|
)
|
|
|
fmt.Println(r)
|
|
|
|