fix FROM instruction erroring when referring to a file

This commit is contained in:
Jeffrey Morgan
2023-08-22 09:39:42 -07:00
parent 0a892419ad
commit a9f6c56652
5 changed files with 47 additions and 115 deletions

View File

@@ -3,20 +3,14 @@ package server
import "testing"
func TestParseModelPath(t *testing.T) {
type input struct {
name string
allowInsecure bool
}
tests := []struct {
name string
args input
arg string
want ModelPath
wantErr error
}{
{
"full path https",
input{"https://example.com/ns/repo:tag", false},
"https://example.com/ns/repo:tag",
ModelPath{
ProtocolScheme: "https",
Registry: "example.com",
@@ -24,17 +18,10 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: "tag",
},
nil,
},
{
"full path http without insecure",
input{"http://example.com/ns/repo:tag", false},
ModelPath{},
ErrInsecureProtocol,
},
{
"full path http with insecure",
input{"http://example.com/ns/repo:tag", true},
"full path http",
"http://example.com/ns/repo:tag",
ModelPath{
ProtocolScheme: "http",
Registry: "example.com",
@@ -42,17 +29,10 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: "tag",
},
nil,
},
{
"full path invalid protocol",
input{"file://example.com/ns/repo:tag", false},
ModelPath{},
ErrInvalidProtocol,
},
{
"no protocol",
input{"example.com/ns/repo:tag", false},
"example.com/ns/repo:tag",
ModelPath{
ProtocolScheme: "https",
Registry: "example.com",
@@ -60,11 +40,10 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: "tag",
},
nil,
},
{
"no registry",
input{"ns/repo:tag", false},
"ns/repo:tag",
ModelPath{
ProtocolScheme: "https",
Registry: DefaultRegistry,
@@ -72,11 +51,10 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: "tag",
},
nil,
},
{
"no namespace",
input{"repo:tag", false},
"repo:tag",
ModelPath{
ProtocolScheme: "https",
Registry: DefaultRegistry,
@@ -84,11 +62,10 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: "tag",
},
nil,
},
{
"no tag",
input{"repo", false},
"repo",
ModelPath{
ProtocolScheme: "https",
Registry: DefaultRegistry,
@@ -96,23 +73,12 @@ func TestParseModelPath(t *testing.T) {
Repository: "repo",
Tag: DefaultTag,
},
nil,
},
{
"invalid image format",
input{"example.com/a/b/c", false},
ModelPath{},
ErrInvalidImageFormat,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got, err := ParseModelPath(tc.args.name, tc.args.allowInsecure)
if err != tc.wantErr {
t.Errorf("got: %q want: %q", err, tc.wantErr)
}
got := ParseModelPath(tc.arg)
if got != tc.want {
t.Errorf("got: %q want: %q", got, tc.want)