images_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package server
  2. import (
  3. "context"
  4. "strings"
  5. "testing"
  6. "github.com/ollama/ollama/api"
  7. )
  8. func TestPushModel(t *testing.T) {
  9. noOpProgress := func(resp api.ProgressResponse) {}
  10. tests := []struct {
  11. modelStr string
  12. regOpts *registryOptions
  13. wantErr string
  14. }{
  15. {
  16. modelStr: "http://example.com/namespace/repo:tag",
  17. regOpts: &registryOptions{Insecure: false},
  18. wantErr: "insecure protocol http",
  19. },
  20. {
  21. modelStr: "docker://Example/repo:tag",
  22. regOpts: &registryOptions{},
  23. wantErr: "namespace must be lowercase, but is Example",
  24. },
  25. {
  26. modelStr: "docker://example/Repo:tag",
  27. regOpts: &registryOptions{},
  28. wantErr: "model name must be lowercase, but is Repo",
  29. },
  30. }
  31. for _, tt := range tests {
  32. t.Run(tt.modelStr, func(t *testing.T) {
  33. err := PushModel(context.Background(), tt.modelStr, tt.regOpts, noOpProgress)
  34. if tt.wantErr != "" {
  35. if err == nil {
  36. t.Errorf("PushModel() error = %v, wantErr %v", err, tt.wantErr)
  37. } else if !strings.Contains(err.Error(), tt.wantErr) {
  38. t.Errorf("PushModel() error = %v, wantErr %v", err, tt.wantErr)
  39. }
  40. return
  41. }
  42. })
  43. }
  44. }