modelpath_test.go 1.63 KB
Newer Older
1
2
3
4
5
6
package server

import "testing"

func TestParseModelPath(t *testing.T) {
	tests := []struct {
Michael Yang's avatar
Michael Yang committed
7
8
9
		name string
		arg  string
		want ModelPath
10
11
12
	}{
		{
			"full path https",
13
			"https://example.com/ns/repo:tag",
14
15
16
17
18
19
20
21
22
			ModelPath{
				ProtocolScheme: "https",
				Registry:       "example.com",
				Namespace:      "ns",
				Repository:     "repo",
				Tag:            "tag",
			},
		},
		{
23
24
			"full path http",
			"http://example.com/ns/repo:tag",
25
26
27
28
29
30
31
32
33
34
			ModelPath{
				ProtocolScheme: "http",
				Registry:       "example.com",
				Namespace:      "ns",
				Repository:     "repo",
				Tag:            "tag",
			},
		},
		{
			"no protocol",
35
			"example.com/ns/repo:tag",
36
37
38
39
40
41
42
43
44
45
			ModelPath{
				ProtocolScheme: "https",
				Registry:       "example.com",
				Namespace:      "ns",
				Repository:     "repo",
				Tag:            "tag",
			},
		},
		{
			"no registry",
46
			"ns/repo:tag",
47
48
49
50
51
52
53
54
55
56
			ModelPath{
				ProtocolScheme: "https",
				Registry:       DefaultRegistry,
				Namespace:      "ns",
				Repository:     "repo",
				Tag:            "tag",
			},
		},
		{
			"no namespace",
57
			"repo:tag",
58
59
60
61
62
63
64
65
66
67
			ModelPath{
				ProtocolScheme: "https",
				Registry:       DefaultRegistry,
				Namespace:      DefaultNamespace,
				Repository:     "repo",
				Tag:            "tag",
			},
		},
		{
			"no tag",
68
			"repo",
69
70
71
72
73
74
75
76
77
78
79
80
			ModelPath{
				ProtocolScheme: "https",
				Registry:       DefaultRegistry,
				Namespace:      DefaultNamespace,
				Repository:     "repo",
				Tag:            DefaultTag,
			},
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
81
			got := ParseModelPath(tc.arg)
82
83
84
85
86
87
88

			if got != tc.want {
				t.Errorf("got: %q want: %q", got, tc.want)
			}
		})
	}
}