-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package oci | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_parseURI(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
uri string | ||
imageName string | ||
wantUri string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
uri: "oci://registry.replicated.com/app-slug/unstable", | ||
imageName: "replicated-preflight", | ||
wantUri: "registry.replicated.com/app-slug/unstable/replicated-preflight:latest", | ||
}, | ||
{ | ||
name: "no path in uri", | ||
uri: "oci://registry.replicated.com", | ||
imageName: "replicated-preflight", | ||
wantUri: "registry.replicated.com/replicated-preflight:latest", | ||
}, | ||
{ | ||
name: "hostname with port", | ||
uri: "oci://localhost:5000/some/path", | ||
imageName: "replicated-preflight", | ||
wantUri: "localhost:5000/some/path/replicated-preflight:latest", | ||
}, | ||
{ | ||
name: "uri with tags", | ||
uri: "oci://localhost:5000/some/path:tag", | ||
imageName: "replicated-preflight", | ||
wantUri: "localhost:5000/some/path/replicated-preflight:tag", | ||
}, | ||
{ | ||
name: "empty uri", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid uri", | ||
uri: "registry.replicated.com/app-slug/unstable", | ||
imageName: "replicated-preflight", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid uri", | ||
uri: "https://registry.replicated.com/app-slug/unstable", | ||
imageName: "replicated-preflight", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := parseURI(tt.uri, tt.imageName) | ||
require.Equalf(t, tt.wantErr, err != nil, "parseURI() error = %v, wantErr %v", err, tt.wantErr) | ||
assert.Equalf(t, tt.wantUri, got, "parseURI() = %v, want %v", got, tt.wantUri) | ||
}) | ||
} | ||
} |