routes_delete_test.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package server
  2. import (
  3. "fmt"
  4. "net/http"
  5. "path/filepath"
  6. "testing"
  7. "github.com/ollama/ollama/api"
  8. )
  9. func TestDelete(t *testing.T) {
  10. p := t.TempDir()
  11. t.Setenv("OLLAMA_MODELS", p)
  12. var s Server
  13. w := createRequest(t, s.CreateModelHandler, api.CreateRequest{
  14. Name: "test",
  15. Modelfile: fmt.Sprintf("FROM %s", createBinFile(t, nil, nil)),
  16. })
  17. if w.Code != http.StatusOK {
  18. t.Fatalf("expected status code 200, actual %d", w.Code)
  19. }
  20. w = createRequest(t, s.CreateModelHandler, api.CreateRequest{
  21. Name: "test2",
  22. Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ .System }} {{ .Prompt }}", createBinFile(t, nil, nil)),
  23. })
  24. if w.Code != http.StatusOK {
  25. t.Fatalf("expected status code 200, actual %d", w.Code)
  26. }
  27. checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{
  28. filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"),
  29. filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test2", "latest"),
  30. })
  31. checkFileExists(t, filepath.Join(p, "blobs", "*"), []string{
  32. filepath.Join(p, "blobs", "sha256-8f2c2167d789c6b2302dff965160fa5029f6a24096d262c1cbb469f21a045382"),
  33. filepath.Join(p, "blobs", "sha256-a4e5e156ddec27e286f75328784d7106b60a4eb1d246e950a001a3f944fbda99"),
  34. filepath.Join(p, "blobs", "sha256-ca239d7bd8ea90e4a5d2e6bf88f8d74a47b14336e73eb4e18bed4dd325018116"),
  35. filepath.Join(p, "blobs", "sha256-fe7ac77b725cda2ccad03f88a880ecdfd7a33192d6cae08fce2c0ee1455991ed"),
  36. })
  37. w = createRequest(t, s.DeleteModelHandler, api.DeleteRequest{Name: "test"})
  38. if w.Code != http.StatusOK {
  39. t.Fatalf("expected status code 200, actual %d", w.Code)
  40. }
  41. checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{
  42. filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test2", "latest"),
  43. })
  44. checkFileExists(t, filepath.Join(p, "blobs", "*"), []string{
  45. filepath.Join(p, "blobs", "sha256-8f2c2167d789c6b2302dff965160fa5029f6a24096d262c1cbb469f21a045382"),
  46. filepath.Join(p, "blobs", "sha256-a4e5e156ddec27e286f75328784d7106b60a4eb1d246e950a001a3f944fbda99"),
  47. filepath.Join(p, "blobs", "sha256-fe7ac77b725cda2ccad03f88a880ecdfd7a33192d6cae08fce2c0ee1455991ed"),
  48. })
  49. w = createRequest(t, s.DeleteModelHandler, api.DeleteRequest{Name: "test2"})
  50. if w.Code != http.StatusOK {
  51. t.Fatalf("expected status code 200, actual %d", w.Code)
  52. }
  53. checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{})
  54. checkFileExists(t, filepath.Join(p, "blobs", "*"), []string{})
  55. }