Skip to content

Commit

Permalink
add error wrap for target
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

increase coverage

resolve comment

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Mar 25, 2024
1 parent 82b8925 commit fc8679d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (opts *Target) Parse() error {
opts.Type = TargetTypeRemote
if _, err := registry.ParseReference(opts.RawReference); err != nil {
return &oerrors.Error{
Err: fmt.Errorf("%q is an invalid reference", opts.RawReference),
Err: fmt.Errorf("%w: %q", err, opts.RawReference),
Recommendation: "Please make sure the provided reference is in the form of <registry>/<repo>[:tag|@digest]",
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("ORAS beginners:", func() {

It("should fail if the provided reference is not valid", func() {
err := ORAS("push", "/oras").ExpectFailure().Exec().Err
gomega.Expect(err).Should(gbytes.Say(`Error: "/oras" is an invalid reference`))
gomega.Expect(err).Should(gbytes.Say(`Error: invalid reference: invalid registry "": "/oras" is an invalid reference`))
gomega.Expect(err).Should(gbytes.Say(regexp.QuoteMeta("Please make sure the provided reference is in the form of <registry>/<repo>[:tag|@digest]")))
})

Expand Down
4 changes: 4 additions & 0 deletions test/e2e/suite/command/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ var _ = Describe("ORAS beginners:", func() {
ORAS("tag", RegistryRef(ZOTHost, ImageRepo, InvalidTag), "tagged").ExpectFailure().MatchErrKeyWords(RegistryErrorPrefix).Exec()
})

It("should fail when the given reference is invalid", func() {
ORAS("tag", fmt.Sprintf("%s/%s:%s", ZOTHost, InvalidRepo, "test"), "latest").ExpectFailure().MatchErrKeyWords("Error:", "unable to add tag", "invalid reference").Exec()
})

It("should fail and show detailed error description if no argument provided", func() {
err := ORAS("tag").ExpectFailure().Exec().Err
gomega.Expect(err).Should(gbytes.Say("Error"))
Expand Down

0 comments on commit fc8679d

Please sign in to comment.