modelpath_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package server
  2. import "testing"
  3. func TestParseModelPath(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. arg string
  7. want ModelPath
  8. }{
  9. {
  10. "full path https",
  11. "https://example.com/ns/repo:tag",
  12. ModelPath{
  13. ProtocolScheme: "https",
  14. Registry: "example.com",
  15. Namespace: "ns",
  16. Repository: "repo",
  17. Tag: "tag",
  18. },
  19. },
  20. {
  21. "full path http",
  22. "http://example.com/ns/repo:tag",
  23. ModelPath{
  24. ProtocolScheme: "http",
  25. Registry: "example.com",
  26. Namespace: "ns",
  27. Repository: "repo",
  28. Tag: "tag",
  29. },
  30. },
  31. {
  32. "no protocol",
  33. "example.com/ns/repo:tag",
  34. ModelPath{
  35. ProtocolScheme: "https",
  36. Registry: "example.com",
  37. Namespace: "ns",
  38. Repository: "repo",
  39. Tag: "tag",
  40. },
  41. },
  42. {
  43. "no registry",
  44. "ns/repo:tag",
  45. ModelPath{
  46. ProtocolScheme: "https",
  47. Registry: DefaultRegistry,
  48. Namespace: "ns",
  49. Repository: "repo",
  50. Tag: "tag",
  51. },
  52. },
  53. {
  54. "no namespace",
  55. "repo:tag",
  56. ModelPath{
  57. ProtocolScheme: "https",
  58. Registry: DefaultRegistry,
  59. Namespace: DefaultNamespace,
  60. Repository: "repo",
  61. Tag: "tag",
  62. },
  63. },
  64. {
  65. "no tag",
  66. "repo",
  67. ModelPath{
  68. ProtocolScheme: "https",
  69. Registry: DefaultRegistry,
  70. Namespace: DefaultNamespace,
  71. Repository: "repo",
  72. Tag: DefaultTag,
  73. },
  74. },
  75. }
  76. for _, tc := range tests {
  77. t.Run(tc.name, func(t *testing.T) {
  78. got := ParseModelPath(tc.arg)
  79. if got != tc.want {
  80. t.Errorf("got: %q want: %q", got, tc.want)
  81. }
  82. })
  83. }
  84. }