|
@@ -632,7 +632,7 @@ func TestCreateVersion(t *testing.T){
|
|
|
envconfig.LoadConfig()
|
|
|
var s Server
|
|
|
|
|
|
- w := createRequest(t, s.CreateModelHandler, api.CreateRequest{
|
|
|
+ w := createRequest(t, s.CreateModelHandler, api.CreateRequest{
|
|
|
Name: "test",
|
|
|
Modelfile: fmt.Sprintf("FROM %s\nOLLAMA 0.2.3\nLICENSE MIT\nLICENSE Apache-2.0", createBinFile(t, nil, nil)),
|
|
|
Stream: &stream,
|
|
@@ -642,9 +642,59 @@ func TestCreateVersion(t *testing.T){
|
|
|
t.Fatalf("expected status code 200, actual %d", w.Code)
|
|
|
}
|
|
|
|
|
|
+ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{
|
|
|
+ filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"),
|
|
|
+ })
|
|
|
+
|
|
|
+ f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ bts := json.NewDecoder(f)
|
|
|
+
|
|
|
+ var m Manifest
|
|
|
+ if err := bts.Decode(&m); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if m.Ollama != "0.2.3" {
|
|
|
+ t.Errorf("got %s != want 0.2.3", m.Ollama)
|
|
|
+ }
|
|
|
+
|
|
|
+ t.Run("no version", func(t *testing.T) {
|
|
|
+ w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
|
|
|
+ Name: "noversion",
|
|
|
+ Modelfile: fmt.Sprintf("FROM %s\nLICENSE MIT\nLICENSE Apache-2.0", createBinFile(t, nil, nil)),
|
|
|
+ Stream: &stream,
|
|
|
+ })
|
|
|
+
|
|
|
+ if w.Code != http.StatusOK {
|
|
|
+ t.Fatalf("expected status code 200, actual %d", w.Code)
|
|
|
+ }
|
|
|
+
|
|
|
+ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "noversion", "*"), []string{
|
|
|
+ filepath.Join(p, "manifests", "registry.ollama.ai", "library", "noversion", "latest"),
|
|
|
+ })
|
|
|
+
|
|
|
+ f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "noversion", "latest"))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ bts := json.NewDecoder(f)
|
|
|
+ var m Manifest
|
|
|
+ if err := bts.Decode(&m); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if m.Ollama != "" {
|
|
|
+ t.Errorf("got %s != want \"\"", m.Ollama)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
t.Run("invalid version", func(t *testing.T) {
|
|
|
w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
|
|
|
- Name: "test",
|
|
|
+ Name: "invalid",
|
|
|
Modelfile: fmt.Sprintf("FROM %s\nOLLAMA 0..400", createBinFile(t, nil, nil)),
|
|
|
Stream: &stream,
|
|
|
})
|
|
@@ -653,4 +703,35 @@ func TestCreateVersion(t *testing.T){
|
|
|
t.Fatalf("expected status code 400, actual %d", w.Code)
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ t.Run("from valid version", func(t *testing.T) {
|
|
|
+ w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
|
|
|
+ Name: "fromvalid",
|
|
|
+ Modelfile: "FROM test",
|
|
|
+ Stream: &stream,
|
|
|
+ })
|
|
|
+
|
|
|
+ if w.Code != http.StatusOK {
|
|
|
+ t.Fatalf("expected status code 200, actual %d", w.Code)
|
|
|
+ }
|
|
|
+
|
|
|
+ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "fromvalid", "*"), []string{
|
|
|
+ filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest"),
|
|
|
+ })
|
|
|
+
|
|
|
+ f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest"))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ bts := json.NewDecoder(f)
|
|
|
+
|
|
|
+ var m Manifest
|
|
|
+ if err := bts.Decode(&m); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if m.Ollama != "0.2.3" {
|
|
|
+ t.Errorf("got %s != want 0.2.3", m.Ollama)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|