From b669677be90cb83bd9cc8e2cdc26b92863371f41 Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Mon, 29 Jul 2024 14:54:18 -0700 Subject: [PATCH] refactor test --- server/routes_create_test.go | 59 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/server/routes_create_test.go b/server/routes_create_test.go index 1ca225111..c6b61d0d9 100644 --- a/server/routes_create_test.go +++ b/server/routes_create_test.go @@ -661,6 +661,34 @@ func TestCreateVersion(t *testing.T) { 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) { w = createRequest(t, s.CreateModelHandler, api.CreateRequest{ Name: "noversion", @@ -703,35 +731,4 @@ 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) - } - }) }