2023-08-22 04:56:56 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestParseModelPath(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2023-08-22 16:39:42 +00:00
|
|
|
arg string
|
2023-08-22 04:56:56 +00:00
|
|
|
want ModelPath
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"full path https",
|
2023-08-22 16:39:42 +00:00
|
|
|
"https://example.com/ns/repo:tag",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "https",
|
|
|
|
Registry: "example.com",
|
|
|
|
Namespace: "ns",
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: "tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-08-22 16:39:42 +00:00
|
|
|
"full path http",
|
|
|
|
"http://example.com/ns/repo:tag",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "http",
|
|
|
|
Registry: "example.com",
|
|
|
|
Namespace: "ns",
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: "tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"no protocol",
|
2023-08-22 16:39:42 +00:00
|
|
|
"example.com/ns/repo:tag",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "https",
|
|
|
|
Registry: "example.com",
|
|
|
|
Namespace: "ns",
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: "tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"no registry",
|
2023-08-22 16:39:42 +00:00
|
|
|
"ns/repo:tag",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "https",
|
|
|
|
Registry: DefaultRegistry,
|
|
|
|
Namespace: "ns",
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: "tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"no namespace",
|
2023-08-22 16:39:42 +00:00
|
|
|
"repo:tag",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "https",
|
|
|
|
Registry: DefaultRegistry,
|
|
|
|
Namespace: DefaultNamespace,
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: "tag",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"no tag",
|
2023-08-22 16:39:42 +00:00
|
|
|
"repo",
|
2023-08-22 04:56:56 +00:00
|
|
|
ModelPath{
|
|
|
|
ProtocolScheme: "https",
|
|
|
|
Registry: DefaultRegistry,
|
|
|
|
Namespace: DefaultNamespace,
|
|
|
|
Repository: "repo",
|
|
|
|
Tag: DefaultTag,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2023-08-22 16:39:42 +00:00
|
|
|
got := ParseModelPath(tc.arg)
|
2023-08-22 04:56:56 +00:00
|
|
|
|
|
|
|
if got != tc.want {
|
|
|
|
t.Errorf("got: %q want: %q", got, tc.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|