|
@@ -1,6 +1,7 @@
|
|
package model
|
|
package model
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "path/filepath"
|
|
"reflect"
|
|
"reflect"
|
|
"runtime"
|
|
"runtime"
|
|
"testing"
|
|
"testing"
|
|
@@ -15,6 +16,7 @@ func TestParseNameParts(t *testing.T) {
|
|
cases := []struct {
|
|
cases := []struct {
|
|
in string
|
|
in string
|
|
want Name
|
|
want Name
|
|
|
|
+ wantFilepath string
|
|
wantValidDigest bool
|
|
wantValidDigest bool
|
|
}{
|
|
}{
|
|
{
|
|
{
|
|
@@ -25,6 +27,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: "model",
|
|
Model: "model",
|
|
Tag: "tag",
|
|
Tag: "tag",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("host:port", "namespace", "model", "tag"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "host/namespace/model:tag",
|
|
in: "host/namespace/model:tag",
|
|
@@ -34,6 +37,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: "model",
|
|
Model: "model",
|
|
Tag: "tag",
|
|
Tag: "tag",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("host", "namespace", "model", "tag"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "host:port/namespace/model:tag",
|
|
in: "host:port/namespace/model:tag",
|
|
@@ -43,6 +47,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: "model",
|
|
Model: "model",
|
|
Tag: "tag",
|
|
Tag: "tag",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("host:port", "namespace", "model", "tag"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "host/namespace/model",
|
|
in: "host/namespace/model",
|
|
@@ -51,6 +56,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Namespace: "namespace",
|
|
Namespace: "namespace",
|
|
Model: "model",
|
|
Model: "model",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("host", "namespace", "model", "latest"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "host:port/namespace/model",
|
|
in: "host:port/namespace/model",
|
|
@@ -59,6 +65,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Namespace: "namespace",
|
|
Namespace: "namespace",
|
|
Model: "model",
|
|
Model: "model",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("host:port", "namespace", "model", "latest"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "namespace/model",
|
|
in: "namespace/model",
|
|
@@ -66,12 +73,14 @@ func TestParseNameParts(t *testing.T) {
|
|
Namespace: "namespace",
|
|
Namespace: "namespace",
|
|
Model: "model",
|
|
Model: "model",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("registry.ollama.ai", "namespace", "model", "latest"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "model",
|
|
in: "model",
|
|
want: Name{
|
|
want: Name{
|
|
Model: "model",
|
|
Model: "model",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("registry.ollama.ai", "library", "model", "latest"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "h/nn/mm:t",
|
|
in: "h/nn/mm:t",
|
|
@@ -81,6 +90,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: "mm",
|
|
Model: "mm",
|
|
Tag: "t",
|
|
Tag: "t",
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join("h", "nn", "mm", "t"),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: part80 + "/" + part80 + "/" + part80 + ":" + part80,
|
|
in: part80 + "/" + part80 + "/" + part80 + ":" + part80,
|
|
@@ -90,6 +100,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: part80,
|
|
Model: part80,
|
|
Tag: part80,
|
|
Tag: part80,
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join(part80, part80, part80, part80),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: part350 + "/" + part80 + "/" + part80 + ":" + part80,
|
|
in: part350 + "/" + part80 + "/" + part80 + ":" + part80,
|
|
@@ -99,6 +110,7 @@ func TestParseNameParts(t *testing.T) {
|
|
Model: part80,
|
|
Model: part80,
|
|
Tag: part80,
|
|
Tag: part80,
|
|
},
|
|
},
|
|
|
|
+ wantFilepath: filepath.Join(part350, part80, part80, part80),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
in: "@digest",
|
|
in: "@digest",
|
|
@@ -123,6 +135,11 @@ func TestParseNameParts(t *testing.T) {
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("parseName(%q) = %v; want %v", tt.in, got, tt.want)
|
|
t.Errorf("parseName(%q) = %v; want %v", tt.in, got, tt.want)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ got = ParseName(tt.in)
|
|
|
|
+ if tt.wantFilepath != "" && got.Filepath() != tt.wantFilepath {
|
|
|
|
+ t.Errorf("parseName(%q).Filepath() = %q; want %q", tt.in, got.Filepath(), tt.wantFilepath)
|
|
|
|
+ }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|