From b27268aaefa03f401f0f09c1e21b63872288ddc7 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 10 Jun 2024 11:31:34 -0700 Subject: [PATCH] add test --- server/routes_delete_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server/routes_delete_test.go b/server/routes_delete_test.go index d0990009..0f003574 100644 --- a/server/routes_delete_test.go +++ b/server/routes_delete_test.go @@ -1,12 +1,15 @@ package server import ( + "bytes" + "encoding/json" "fmt" "net/http" "path/filepath" "testing" "github.com/ollama/ollama/api" + "github.com/ollama/ollama/types/model" ) func TestDelete(t *testing.T) { @@ -69,3 +72,33 @@ func TestDelete(t *testing.T) { checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{}) checkFileExists(t, filepath.Join(p, "blobs", "*"), []string{}) } + +func TestDeleteDuplicateLayers(t *testing.T) { + p := t.TempDir() + t.Setenv("OLLAMA_MODELS", p) + var s Server + + n := model.ParseName("test") + + var b bytes.Buffer + if err := json.NewEncoder(&b).Encode(&ConfigV2{}); err != nil { + t.Fatal(err) + } + + config, err := NewLayer(&b, "application/vnd.docker.container.image.v1+json") + if err != nil { + t.Fatal(err) + } + + // create a manifest with duplicate layers + if err := WriteManifest(n, config, []*Layer{config}); err != nil { + t.Fatal(err) + } + + w := createRequest(t, s.DeleteModelHandler, api.DeleteRequest{Name: "test"}) + if w.Code != http.StatusOK { + t.Errorf("expected status code 200, actual %d", w.Code) + } + + checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{}) +}