| 1 | /* |
| 2 | Copyright The ORAS Authors. |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | |
| 7 | http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | |
| 9 | Unless required by applicable law or agreed to in writing, software |
| 10 | distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | See the License for the specific language governing permissions and |
| 13 | limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package errutilscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/ |
| 17 | |
| 18 | import ( |
| 19 | "errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/" |
| 20 | "net/httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/" |
| 21 | "net/http/httptestscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/" |
| 22 | "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/" |
| 23 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 24 | |
| 25 | "oras.land/oras-go/v2/registry/remote/errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/" |
| 26 | ) |
| 27 | |
| 28 | func Test_ParseErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/Test_ParseErrorResponse().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 29 | path := "/test" |
| 30 | expectedErrs := errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 31 | { |
| 32 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: "UNAUTHORIZED", |
| 33 | Messagescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Message.: "authentication required", |
| 34 | }, |
| 35 | { |
| 36 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: "NAME_UNKNOWN", |
| 37 | Messagescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Message.: "repository name not known to registry", |
| 38 | }, |
| 39 | } |
| 40 | ts := httptestscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#) { |
| 41 | switch r.URLscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#URL..Pathscip-go gomod github.com/golang/go/src go1.23.0 `net/url`/URL#Path. { |
| 42 | case path: |
| 43 | msg := `{ "errors": [ { "code": "UNAUTHORIZED", "message": "authentication required", "detail": [ { "Type": "repository", "Class": "", "Name": "library/hello-world", "Action": "pull" } ] }, { "code": "NAME_UNKNOWN", "message": "repository name not known to registry" } ] }` |
| 44 | w.WriteHeaderscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusUnauthorized.) |
| 45 | if _, err := w.Writescip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#Write().([]byte(msg)); err != nil { |
| 46 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("failed to write %q: %v", r.URLscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#URL., err) |
| 47 | } |
| 48 | default: |
| 49 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("unexpected access: %s %s", r.Methodscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#Method., r.URLscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#URL.) |
| 50 | w.WriteHeaderscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusNotFoundscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusNotFound.) |
| 51 | } |
| 52 | |
| 53 | })) |
| 54 | defer ts.Closescip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/Server#Close().() |
| 55 | |
| 56 | resp, err := httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Getscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Get().(ts.URLscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/Server#URL. + path) |
| 57 | if err != nil { |
| 58 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("failed to do request: %v", err) |
| 59 | } |
| 60 | err = ParseErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/ParseErrorResponse().(resp) |
| 61 | if err == nil { |
| 62 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, wantErr %v", err, true) |
| 63 | } |
| 64 | |
| 65 | var errResp *errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse# |
| 66 | if ok := errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Asscip-go gomod github.com/golang/go/src go1.23.0 errors/As().(err, &errResp); !ok { |
| 67 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("errors.As(err, &UnexpectedStatusCodeError) = %v, want %v", ok, true) |
| 68 | } |
| 69 | if want := httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/MethodGet.; errResp.Methodscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Method. != want { |
| 70 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() Method = %v, want Method %v", errResp.Methodscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Method., want) |
| 71 | } |
| 72 | if want := httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusUnauthorized.; errResp.StatusCodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#StatusCode. != want { |
| 73 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() StatusCode = %v, want StatusCode %v", errResp.StatusCodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#StatusCode., want) |
| 74 | } |
| 75 | if want := path; errResp.URLscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#URL..Pathscip-go gomod github.com/golang/go/src go1.23.0 `net/url`/URL#Path. != want { |
| 76 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() URL = %v, want URL %v", errResp.URLscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#URL..Pathscip-go gomod github.com/golang/go/src go1.23.0 `net/url`/URL#Path., want) |
| 77 | } |
| 78 | for i, e := range errResp.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Errors. { |
| 79 | if want := expectedErrs[i].Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.; e.Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code. != expectedErrs[i].Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code. { |
| 80 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() Code = %v, want Code %v", e.Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code., want) |
| 81 | } |
| 82 | if want := expectedErrs[i].Messagescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Message.; e.Messagescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Message. != want { |
| 83 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() Message = %v, want Code %v", e.Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code., want) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | errmsg := err.Error() |
| 88 | if want := "401"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 89 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 90 | } |
| 91 | // first error |
| 92 | if want := "unauthorized"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 93 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 94 | } |
| 95 | if want := "authentication required"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 96 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 97 | } |
| 98 | // second error |
| 99 | if want := "name unknown"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 100 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 101 | } |
| 102 | if want := "repository name not known to registry"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 103 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | func Test_ParseErrorResponse_plainscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/Test_ParseErrorResponse_plain().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 108 | ts := httptestscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/.NewServerscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/NewServer().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.HandlerFuncscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/HandlerFunc#(func(w httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#, r *httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Request#) { |
| 109 | w.WriteHeaderscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/ResponseWriter#WriteHeader().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusUnauthorized.) |
| 110 | })) |
| 111 | defer ts.Closescip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/Server#Close().() |
| 112 | |
| 113 | resp, err := httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Getscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Get().(ts.URLscip-go gomod github.com/golang/go/src go1.23.0 `net/http/httptest`/Server#URL.) |
| 114 | if err != nil { |
| 115 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("failed to do request: %v", err) |
| 116 | } |
| 117 | err = ParseErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/ParseErrorResponse().(resp) |
| 118 | if err == nil { |
| 119 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, wantErr %v", err, true) |
| 120 | } |
| 121 | errmsg := err.Error() |
| 122 | if want := "401"; !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 123 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 124 | } |
| 125 | if want := httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusTextscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusText().(httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/StatusUnauthorized.); !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(errmsg, want) { |
| 126 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ParseErrorResponse() error = %v, want err message %v", err, want) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | func TestIsErrorCodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/TestIsErrorCode().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 131 | tests := []struct { |
| 132 | name string |
| 133 | err error |
| 134 | code string |
| 135 | want bool |
| 136 | }{ |
| 137 | { |
| 138 | name: "test errcode.Error, same code", |
| 139 | err: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#{ |
| 140 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 141 | }, |
| 142 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 143 | want: true, |
| 144 | }, |
| 145 | { |
| 146 | name: "test errcode.Error, different code", |
| 147 | err: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#{ |
| 148 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeUnauthorizedscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeUnauthorized., |
| 149 | }, |
| 150 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 151 | want: false, |
| 152 | }, |
| 153 | { |
| 154 | name: "test errcode.Errors containing single error, same code", |
| 155 | err: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 156 | { |
| 157 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 158 | }, |
| 159 | }, |
| 160 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 161 | want: true, |
| 162 | }, |
| 163 | { |
| 164 | name: "test errcode.Errors containing single error, different code", |
| 165 | err: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 166 | { |
| 167 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 168 | }, |
| 169 | }, |
| 170 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 171 | want: true, |
| 172 | }, |
| 173 | { |
| 174 | name: "test errcode.Errors containing multiple errors, same code", |
| 175 | err: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 176 | { |
| 177 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 178 | }, |
| 179 | { |
| 180 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeUnauthorizedscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeUnauthorized., |
| 181 | }, |
| 182 | }, |
| 183 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 184 | want: false, |
| 185 | }, |
| 186 | { |
| 187 | name: "test errcode.ErrorResponse containing single error, same code", |
| 188 | err: &errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#{ |
| 189 | Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Errors.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 190 | { |
| 191 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 192 | }, |
| 193 | }, |
| 194 | }, |
| 195 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 196 | want: true, |
| 197 | }, |
| 198 | { |
| 199 | name: "test errcode.ErrorResponse containing single error, different code", |
| 200 | err: &errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#{ |
| 201 | Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Errors.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 202 | { |
| 203 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeUnauthorizedscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeUnauthorized., |
| 204 | }, |
| 205 | }, |
| 206 | }, |
| 207 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 208 | want: false, |
| 209 | }, |
| 210 | { |
| 211 | name: "test errcode.ErrorResponse containing multiple errors, same code", |
| 212 | err: &errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorResponsescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#{ |
| 213 | Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorResponse#Errors.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.Errorsscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Errors#{ |
| 214 | { |
| 215 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 216 | }, |
| 217 | { |
| 218 | Codescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/Error#Code.: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeUnauthorizedscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeUnauthorized., |
| 219 | }, |
| 220 | }, |
| 221 | }, |
| 222 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 223 | want: false, |
| 224 | }, |
| 225 | { |
| 226 | name: "test unstructured error", |
| 227 | err: errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().(errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown.), |
| 228 | code: errcodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/.ErrorCodeNameUnknownscip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/errcode`/ErrorCodeNameUnknown., |
| 229 | want: false, |
| 230 | }, |
| 231 | } |
| 232 | for _, tt := range tests { |
| 233 | t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) { |
| 234 | if got := IsErrorCodescip-go gomod oras.land/oras-go/v2 . `oras.land/oras-go/v2/registry/remote/internal/errutil`/IsErrorCode().(tt.err, tt.code); got != tt.want { |
| 235 | t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("IsErrorCode() = %v, want %v", got, tt.want) |
| 236 | } |
| 237 | }) |
| 238 | } |
| 239 | } |