...
1 package image
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestNameFromRef(t *testing.T) {
10 reg := "gcr.io/edge"
11 image := "talaria"
12 URL := reg + "/" + image
13 sha := "sha256:b2a554383b86e9779cf45115e189f3464b1ce51e1c65888d4cdc483e88114a61"
14 nsURL := reg + "/extra/namespaces/" + image
15
16 tests := []struct {
17 name string
18 ref string
19 expected string
20 }{
21 {"ref with digest", URL + "@" + sha, image},
22 {"ref with tag", URL + ":latest", image},
23 {"ref without tag/digest", URL, image},
24 {"ref with digest -- nested repo", nsURL + "@" + sha, image},
25 {"ref with tag -- nested repo", nsURL + ":latest", image},
26 {"ref without tag/digest -- nested repo", nsURL, image},
27 }
28
29 for _, tc := range tests {
30 result := NameFromRef(tc.ref)
31 assert.Equal(t, tc.expected, result, tc.name)
32 }
33 }
34
View as plain text