mirror of
https://github.com/ollama/ollama.git
synced 2025-05-10 18:06:33 +02:00
This commit copies (without history) the bmizerany/ollama-go repository with the intention of integrating it into the ollama as a replacement for the pushing, and pulling of models, and management of the cache they are pushed and pulled from. New homes for these packages will be determined as they are integrated and we have a better understanding of proper package boundaries.
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package blob
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDigest(t *testing.T) {
|
|
cases := []struct {
|
|
in string
|
|
valid bool
|
|
}{
|
|
{"sha256-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", true},
|
|
{"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", true},
|
|
|
|
// too short
|
|
{"sha256-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde", false},
|
|
{"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde", false},
|
|
|
|
// too long
|
|
{"sha256-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0", false},
|
|
{"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0", false},
|
|
|
|
// invalid prefix
|
|
{"sha255-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", false},
|
|
{"sha255:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", false},
|
|
{"sha256!0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", false},
|
|
|
|
// invalid hex
|
|
{"sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", false},
|
|
{"sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", false},
|
|
}
|
|
|
|
for _, tt := range cases {
|
|
got, err := ParseDigest(tt.in)
|
|
if tt.valid && err != nil {
|
|
t.Errorf("ParseDigest(%q) = %v, %v; want valid", tt.in, got, err)
|
|
}
|
|
want := "sha256:" + tt.in[7:]
|
|
if tt.valid && got.String() != want {
|
|
t.Errorf("ParseDigest(%q).String() = %q, want %q", tt.in, got.String(), want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDigestMarshalText(t *testing.T) {
|
|
const s = `"sha256-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"`
|
|
var d Digest
|
|
if err := json.Unmarshal([]byte(s), &d); err != nil {
|
|
t.Errorf("json.Unmarshal: %v", err)
|
|
}
|
|
out, err := json.Marshal(d)
|
|
if err != nil {
|
|
t.Errorf("json.Marshal: %v", err)
|
|
}
|
|
want := `"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"`
|
|
if string(out) != want {
|
|
t.Errorf("json.Marshal: got %s, want %s", out, want)
|
|
}
|
|
if err := json.Unmarshal([]byte(`"invalid"`), &Digest{}); err == nil {
|
|
t.Errorf("json.Unmarshal: expected error")
|
|
}
|
|
}
|