فهرست منبع

refactor test

Josh Yan 9 ماه پیش
والد
کامیت
e5f03af4d3
1فایلهای تغییر یافته به همراه32 افزوده شده و 28 حذف شده
  1. 32 28
      server/routes_create_test.go

+ 32 - 28
server/routes_create_test.go

@@ -647,6 +647,7 @@ func TestCreateVersion(t *testing.T) {
 	})
 	})
 
 
 	f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"))
 	f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"))
+	defer f.Close()
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -661,34 +662,6 @@ func TestCreateVersion(t *testing.T) {
 		t.Errorf("got %s != want 0.2.3", m.Ollama)
 		t.Errorf("got %s != want 0.2.3", m.Ollama)
 	}
 	}
 
 
-	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)
-
-	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) {
 	t.Run("no version", func(t *testing.T) {
 		w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
 		w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
 			Name:      "noversion",
 			Name:      "noversion",
@@ -731,4 +704,35 @@ func TestCreateVersion(t *testing.T) {
 			t.Fatalf("expected status code 400, actual %d", w.Code)
 			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)
+		}
+	})
 }
 }