x/build/blob: more tests
This commit is contained in:
parent
45ca3c80e8
commit
2751c26da7
@ -7,6 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MaxRefLength = 255
|
||||||
|
|
||||||
type PartKind int
|
type PartKind int
|
||||||
|
|
||||||
// Levels of concreteness
|
// Levels of concreteness
|
||||||
@ -224,7 +226,7 @@ func Parts(s string) iter.Seq2[PartKind, string] {
|
|||||||
s = s[len("https://"):]
|
s = s[len("https://"):]
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s) > 255 || len(s) == 0 {
|
if len(s) > MaxRefLength || len(s) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,11 +5,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// test refs
|
|
||||||
const (
|
|
||||||
refTooLong = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var testRefs = map[string]Ref{
|
var testRefs = map[string]Ref{
|
||||||
"mistral:latest": {name: "mistral", tag: "latest"},
|
"mistral:latest": {name: "mistral", tag: "latest"},
|
||||||
"mistral": {name: "mistral"},
|
"mistral": {name: "mistral"},
|
||||||
@ -38,6 +33,9 @@ var testRefs = map[string]Ref{
|
|||||||
"file:///etc/passwd": {},
|
"file:///etc/passwd": {},
|
||||||
"file:///etc/passwd:latest": {},
|
"file:///etc/passwd:latest": {},
|
||||||
"file:///etc/passwd:latest+u": {},
|
"file:///etc/passwd:latest+u": {},
|
||||||
|
|
||||||
|
strings.Repeat("a", MaxRefLength): {name: strings.Repeat("a", MaxRefLength)},
|
||||||
|
strings.Repeat("a", MaxRefLength+1): {},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRefParts(t *testing.T) {
|
func TestRefParts(t *testing.T) {
|
||||||
@ -48,7 +46,7 @@ func TestRefParts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseRefWithAndWithoutPrefixes(t *testing.T) {
|
func TestParseRef(t *testing.T) {
|
||||||
for s, want := range testRefs {
|
for s, want := range testRefs {
|
||||||
for _, prefix := range []string{"", "https://", "http://"} {
|
for _, prefix := range []string{"", "https://", "http://"} {
|
||||||
// We should get the same results with or without the
|
// We should get the same results with or without the
|
||||||
@ -104,9 +102,11 @@ func TestRefFull(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseRefAllocs(t *testing.T) {
|
func TestParseRefAllocs(t *testing.T) {
|
||||||
// test allocations
|
// test allocations
|
||||||
|
var r Ref
|
||||||
allocs := testing.AllocsPerRun(1000, func() {
|
allocs := testing.AllocsPerRun(1000, func() {
|
||||||
ParseRef("example.com/mistral:7b+Q4_0")
|
r = ParseRef("example.com/mistral:7b+Q4_0")
|
||||||
})
|
})
|
||||||
|
_ = r
|
||||||
if allocs > 0 {
|
if allocs > 0 {
|
||||||
t.Errorf("ParseRef allocs = %v; want 0", allocs)
|
t.Errorf("ParseRef allocs = %v; want 0", allocs)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user