Skip to content

Commit

Permalink
Use name.MustParseReference in some tests (#965)
Browse files Browse the repository at this point in the history
* Use name.MustParseReference in gcrane copy_test.go

* Use name.MustParseReference in check_e2e_test.go
  • Loading branch information
imjasonh committed Mar 22, 2021
1 parent 70c58c0 commit 4a92f6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 4 additions & 12 deletions pkg/gcrane/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ import (
"github.com/google/go-containerregistry/pkg/v1/types"
)

func mustRepo(s string) name.Repository {
repo, err := name.NewRepository(s)
if err != nil {
panic(err)
}
return repo
}

type fakeXCR struct {
h http.Handler
repos map[string]google.Tags
Expand Down Expand Up @@ -206,15 +198,15 @@ func TestCopy(t *testing.T) {

func TestRename(t *testing.T) {
c := copier{
srcRepo: mustRepo("xcr.io/foo"),
dstRepo: mustRepo("xcr.io/bar"),
srcRepo: name.MustParseReference("xcr.io/foo").Context(),
dstRepo: name.MustParseReference("xcr.io/bar").Context(),
}

got, err := c.rename(mustRepo("xcr.io/foo/sub/repo"))
got, err := c.rename(name.MustParseReference("xcr.io/foo/sub/repo").Context())
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
want := mustRepo("xcr.io/bar/sub/repo")
want := name.MustParseReference("xcr.io/bar/sub/repo").Context()

if want.String() != got.String() {
t.Errorf("%s != %s", want, got)
Expand Down
12 changes: 6 additions & 6 deletions pkg/v1/remote/check_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestCheckPushPermission_Real(t *testing.T) {
// Tests should not run in an environment where these registries can
// be pushed to.
for _, r := range []name.Reference{
mustNewTag(t, "ubuntu"),
mustNewTag(t, "google/cloud-sdk"),
mustNewTag(t, "microsoft/dotnet:sdk"),
mustNewTag(t, "gcr.io/non-existent-project/made-up"),
mustNewTag(t, "gcr.io/google-containers/foo"),
mustNewTag(t, "quay.io/username/reponame"),
name.MustParseReference("ubuntu"),
name.MustParseReference("google/cloud-sdk"),
name.MustParseReference("microsoft/dotnet:sdk"),
name.MustParseReference("gcr.io/non-existent-project/made-up"),
name.MustParseReference("gcr.io/google-containers/foo"),
name.MustParseReference("quay.io/username/reponame"),
} {
t.Run(r.String(), func(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 4a92f6c

Please sign in to comment.