Skip to content

Commit 4a92f6c

Browse files
authored
Use name.MustParseReference in some tests (#965)
* Use name.MustParseReference in gcrane copy_test.go * Use name.MustParseReference in check_e2e_test.go
1 parent 70c58c0 commit 4a92f6c

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

pkg/gcrane/copy_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ import (
4242
"github.com/google/go-containerregistry/pkg/v1/types"
4343
)
4444

45-
func mustRepo(s string) name.Repository {
46-
repo, err := name.NewRepository(s)
47-
if err != nil {
48-
panic(err)
49-
}
50-
return repo
51-
}
52-
5345
type fakeXCR struct {
5446
h http.Handler
5547
repos map[string]google.Tags
@@ -206,15 +198,15 @@ func TestCopy(t *testing.T) {
206198

207199
func TestRename(t *testing.T) {
208200
c := copier{
209-
srcRepo: mustRepo("xcr.io/foo"),
210-
dstRepo: mustRepo("xcr.io/bar"),
201+
srcRepo: name.MustParseReference("xcr.io/foo").Context(),
202+
dstRepo: name.MustParseReference("xcr.io/bar").Context(),
211203
}
212204

213-
got, err := c.rename(mustRepo("xcr.io/foo/sub/repo"))
205+
got, err := c.rename(name.MustParseReference("xcr.io/foo/sub/repo").Context())
214206
if err != nil {
215207
t.Fatalf("unexpected err: %v", err)
216208
}
217-
want := mustRepo("xcr.io/bar/sub/repo")
209+
want := name.MustParseReference("xcr.io/bar/sub/repo").Context()
218210

219211
if want.String() != got.String() {
220212
t.Errorf("%s != %s", want, got)

pkg/v1/remote/check_e2e_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ func TestCheckPushPermission_Real(t *testing.T) {
2828
// Tests should not run in an environment where these registries can
2929
// be pushed to.
3030
for _, r := range []name.Reference{
31-
mustNewTag(t, "ubuntu"),
32-
mustNewTag(t, "google/cloud-sdk"),
33-
mustNewTag(t, "microsoft/dotnet:sdk"),
34-
mustNewTag(t, "gcr.io/non-existent-project/made-up"),
35-
mustNewTag(t, "gcr.io/google-containers/foo"),
36-
mustNewTag(t, "quay.io/username/reponame"),
31+
name.MustParseReference("ubuntu"),
32+
name.MustParseReference("google/cloud-sdk"),
33+
name.MustParseReference("microsoft/dotnet:sdk"),
34+
name.MustParseReference("gcr.io/non-existent-project/made-up"),
35+
name.MustParseReference("gcr.io/google-containers/foo"),
36+
name.MustParseReference("quay.io/username/reponame"),
3737
} {
3838
t.Run(r.String(), func(t *testing.T) {
3939
t.Parallel()

0 commit comments

Comments
 (0)