build/blob: break out test refs for other tests/fuzzing

This commit is contained in:
Blake Mizerany 2024-04-02 11:38:10 -07:00
parent aff7970628
commit 9959da05de

View File

@ -7,6 +7,22 @@ const (
refTooLong = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
var testRefs = map[string]Ref{
"mistral:latest": {name: "mistral", tag: "latest"},
"mistral": {name: "mistral"},
"mistral:30B": {name: "mistral", tag: "30B"},
"mistral:7b": {name: "mistral", tag: "7b"},
"mistral:7b+Q4_0": {name: "mistral", tag: "7b", build: "Q4_0"},
"mistral+KQED": {name: "mistral", build: "KQED"},
"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"},
"llama2:+": {name: "llama2"},
// invalid
"mistral:7b+Q4_0:latest": {},
"mi tral": {},
}
func TestRefParts(t *testing.T) {
const wantNumParts = 5
var ref Ref
@ -16,60 +32,11 @@ func TestRefParts(t *testing.T) {
}
func TestParseRef(t *testing.T) {
cases := []struct {
in string
want Ref
}{
{"mistral:latest", Ref{
name: "mistral",
tag: "latest",
}},
{"mistral", Ref{
name: "mistral",
}},
{"mistral:30B", Ref{
name: "mistral",
tag: "30B",
}},
{"mistral:7b", Ref{
name: "mistral",
tag: "7b",
}},
{"mistral:7b+Q4_0", Ref{
name: "mistral",
tag: "7b",
build: "Q4_0",
}},
{"mistral+KQED", Ref{
name: "mistral",
build: "KQED",
}},
{"mistral.x-3:7b+Q4_0", Ref{
name: "mistral.x-3",
tag: "7b",
build: "Q4_0",
}},
// lowecase build
{"mistral:7b+q4_0", Ref{
name: "mistral",
tag: "7b",
build: "Q4_0",
}},
{"llama2:+", Ref{name: "llama2"}},
// Invalid
{"mistral:7b+Q4_0:latest", Ref{}},
{"mi tral", Ref{}},
// too long
{refTooLong, Ref{}},
}
for _, tt := range cases {
t.Run(tt.in, func(t *testing.T) {
got := ParseRef(tt.in)
if got != tt.want {
t.Errorf("ParseRef(%q) = %q; want %q", tt.in, got, tt.want)
for s, want := range testRefs {
t.Run(s, func(t *testing.T) {
got := ParseRef(s)
if got != want {
t.Errorf("ParseRef(%q) = %q; want %q", s, got, want)
}
})
}