|
| 1 | +package catalognext |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/google/go-containerregistry/pkg/v1/remote/transport" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestIsNotFoundError(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + err error |
| 16 | + expected bool |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "manifest unknown", |
| 20 | + err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.ManifestUnknownErrorCode}}}, |
| 21 | + expected: true, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "name unknown", |
| 25 | + err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.NameUnknownErrorCode}}}, |
| 26 | + expected: true, |
| 27 | + }, |
| 28 | + { |
| 29 | + name: "wrapped manifest unknown", |
| 30 | + err: fmt.Errorf("fetch failed: %w", &transport.Error{Errors: []transport.Diagnostic{{Code: transport.ManifestUnknownErrorCode}}}), |
| 31 | + expected: true, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "unauthorized error", |
| 35 | + err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.UnauthorizedErrorCode}}}, |
| 36 | + expected: false, |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "non-transport error", |
| 40 | + err: fmt.Errorf("network timeout"), |
| 41 | + expected: false, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "transport error with no diagnostics", |
| 45 | + err: &transport.Error{StatusCode: http.StatusNotFound}, |
| 46 | + expected: false, |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "multiple diagnostics with one match", |
| 50 | + err: &transport.Error{Errors: []transport.Diagnostic{ |
| 51 | + {Code: transport.UnauthorizedErrorCode}, |
| 52 | + {Code: transport.ManifestUnknownErrorCode}, |
| 53 | + }}, |
| 54 | + expected: true, |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + for _, tt := range tests { |
| 59 | + t.Run(tt.name, func(t *testing.T) { |
| 60 | + assert.Equal(t, tt.expected, isNotFoundError(tt.err)) |
| 61 | + }) |
| 62 | + } |
| 63 | +} |
0 commit comments