ref_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package blob
  2. import "testing"
  3. // test refs
  4. const (
  5. refTooLong = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  6. )
  7. var testRefs = map[string]Ref{
  8. "mistral:latest": {name: "mistral", tag: "latest"},
  9. "mistral": {name: "mistral"},
  10. "mistral:30B": {name: "mistral", tag: "30B"},
  11. "mistral:7b": {name: "mistral", tag: "7b"},
  12. "mistral:7b+Q4_0": {name: "mistral", tag: "7b", build: "Q4_0"},
  13. "mistral+KQED": {name: "mistral", build: "KQED"},
  14. "mistral.x-3:7b+Q4_0": {name: "mistral.x-3", tag: "7b", build: "Q4_0"},
  15. "mistral:7b+q4_0": {name: "mistral", tag: "7b", build: "Q4_0"},
  16. "llama2": {name: "llama2"},
  17. // invalid
  18. "mistral:7b+Q4_0:latest": {},
  19. "mi tral": {},
  20. }
  21. func TestRefParts(t *testing.T) {
  22. const wantNumParts = 5
  23. var ref Ref
  24. if len(ref.Parts()) != wantNumParts {
  25. t.Errorf("Parts() = %d; want %d", len(ref.Parts()), wantNumParts)
  26. }
  27. }
  28. func TestParseRef(t *testing.T) {
  29. for s, want := range testRefs {
  30. t.Run(s, func(t *testing.T) {
  31. got := ParseRef(s)
  32. if got != want {
  33. t.Errorf("ParseRef(%q) = %q; want %q", s, got, want)
  34. }
  35. // test round-trip
  36. if ParseRef(got.String()) != got {
  37. t.Errorf("String() = %q; want %q", got.String(), s)
  38. }
  39. })
  40. }
  41. }
  42. func TestRefFull(t *testing.T) {
  43. const empty = "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/!(MISSING NAME):!(MISSING TAG)+!(MISSING BUILD)"
  44. cases := []struct {
  45. in string
  46. wantFull string
  47. }{
  48. {"", empty},
  49. {"example.com/mistral:7b+x", "!(MISSING DOMAIN)/example.com/mistral:7b+X"},
  50. {"example.com/mistral:7b+Q4_0", "!(MISSING DOMAIN)/example.com/mistral:7b+Q4_0"},
  51. {"example.com/x/mistral:latest", "example.com/x/mistral:latest+!(MISSING BUILD)"},
  52. {"example.com/x/mistral:latest+Q4_0", "example.com/x/mistral:latest+Q4_0"},
  53. {"mistral:7b+x", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+X"},
  54. {"mistral:7b+q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"},
  55. {"mistral:7b+Q4_0", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:7b+Q4_0"},
  56. {"mistral:latest", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:latest+!(MISSING BUILD)"},
  57. {"mistral", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:!(MISSING TAG)+!(MISSING BUILD)"},
  58. {"mistral:30b", "!(MISSING DOMAIN)/!(MISSING NAMESPACE)/mistral:30b+!(MISSING BUILD)"},
  59. }
  60. for _, tt := range cases {
  61. t.Run(tt.in, func(t *testing.T) {
  62. ref := ParseRef(tt.in)
  63. t.Logf("ParseRef(%q) = %#v", tt.in, ref)
  64. if g := ref.Full(); g != tt.wantFull {
  65. t.Errorf("Full(%q) = %q; want %q", tt.in, g, tt.wantFull)
  66. }
  67. })
  68. }
  69. }