build/blob: test ParseRef round-trip
This commit is contained in:
parent
9959da05de
commit
eb75418be9
@ -204,6 +204,9 @@ func ParseRef(s string) Ref {
|
|||||||
switch state {
|
switch state {
|
||||||
case build:
|
case build:
|
||||||
r.build = s[i+1 : j]
|
r.build = s[i+1 : j]
|
||||||
|
if r.build == "" {
|
||||||
|
return Ref{}
|
||||||
|
}
|
||||||
r.build = strings.ToUpper(r.build)
|
r.build = strings.ToUpper(r.build)
|
||||||
state, j = tag, i
|
state, j = tag, i
|
||||||
default:
|
default:
|
||||||
@ -213,6 +216,9 @@ func ParseRef(s string) Ref {
|
|||||||
switch state {
|
switch state {
|
||||||
case build, tag:
|
case build, tag:
|
||||||
r.tag = s[i+1 : j]
|
r.tag = s[i+1 : j]
|
||||||
|
if r.tag == "" {
|
||||||
|
return Ref{}
|
||||||
|
}
|
||||||
state, j = name, i
|
state, j = name, i
|
||||||
default:
|
default:
|
||||||
return Ref{}
|
return Ref{}
|
||||||
|
@ -16,7 +16,7 @@ var testRefs = map[string]Ref{
|
|||||||
"mistral+KQED": {name: "mistral", build: "KQED"},
|
"mistral+KQED": {name: "mistral", build: "KQED"},
|
||||||
"mistral.x-3:7b+Q4_0": {name: "mistral.x-3", tag: "7b", build: "Q4_0"},
|
"mistral.x-3:7b+Q4_0": {name: "mistral.x-3", tag: "7b", build: "Q4_0"},
|
||||||
"mistral:7b+q4_0": {name: "mistral", tag: "7b", build: "Q4_0"},
|
"mistral:7b+q4_0": {name: "mistral", tag: "7b", build: "Q4_0"},
|
||||||
"llama2:+": {name: "llama2"},
|
"llama2": {name: "llama2"},
|
||||||
|
|
||||||
// invalid
|
// invalid
|
||||||
"mistral:7b+Q4_0:latest": {},
|
"mistral:7b+Q4_0:latest": {},
|
||||||
@ -38,6 +38,11 @@ func TestParseRef(t *testing.T) {
|
|||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("ParseRef(%q) = %q; want %q", s, got, want)
|
t.Errorf("ParseRef(%q) = %q; want %q", s, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test round-trip
|
||||||
|
if ParseRef(got.String()) != got {
|
||||||
|
t.Errorf("String() = %q; want %q", got.String(), s)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,6 +61,7 @@ func TestRefFull(t *testing.T) {
|
|||||||
{"example.com/x/mistral:latest+Q4_0", "example.com/x/mistral:latest+Q4_0"},
|
{"example.com/x/mistral:latest+Q4_0", "example.com/x/mistral:latest+Q4_0"},
|
||||||
|
|
||||||
{"mistral:7b+x", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+X"},
|
{"mistral:7b+x", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+X"},
|
||||||
|
{"mistral:7b+q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"},
|
||||||
{"mistral:7b+Q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"},
|
{"mistral:7b+Q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"},
|
||||||
{"mistral:latest", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:latest+!(MISSING BUILD)"},
|
{"mistral:latest", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:latest+!(MISSING BUILD)"},
|
||||||
{"mistral", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:!(MISSING TAG)+!(MISSING BUILD)"},
|
{"mistral", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:!(MISSING TAG)+!(MISSING BUILD)"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user