mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-16 16:34:09 +02:00
chore: do not use sentinel errors when unneeded
- main reason being it's a burden to always define sentinel errors at global scope, wrap them with `%w` instead of using a string directly - only use sentinel errors when it has to be checked using `errors.Is` - replace all usage of these sentinel errors in `fmt.Errorf` with direct strings that were in the sentinel error - exclude the sentinel error definition requirement from .golangci.yml - update unit tests to use ContainersError instead of ErrorIs so it stays as a "not a change detector test" without requiring a sentinel error
This commit is contained in:
@@ -37,21 +37,18 @@ func Test_Fetch(t *testing.T) {
|
||||
responseStatus int
|
||||
responseBody io.ReadCloser
|
||||
rootNode *html.Node
|
||||
errWrapped error
|
||||
errMessage string
|
||||
}{
|
||||
"context canceled": {
|
||||
ctx: canceledCtx,
|
||||
url: "https://example.com/path",
|
||||
errWrapped: context.Canceled,
|
||||
errMessage: `Get "https://example.com/path": context canceled`,
|
||||
},
|
||||
"response status not ok": {
|
||||
ctx: context.Background(),
|
||||
url: "https://example.com/path",
|
||||
responseStatus: http.StatusNotFound,
|
||||
errWrapped: ErrHTTPStatusCodeNotOK,
|
||||
errMessage: `HTTP status code is not OK: 404 Not Found`,
|
||||
errMessage: `HTTP status code not OK: 404 Not Found`,
|
||||
},
|
||||
"success": {
|
||||
ctx: context.Background(),
|
||||
@@ -86,9 +83,10 @@ func Test_Fetch(t *testing.T) {
|
||||
|
||||
rootNode, err := Fetch(testCase.ctx, client, testCase.url)
|
||||
|
||||
assert.ErrorIs(t, err, testCase.errWrapped)
|
||||
if testCase.errWrapped != nil {
|
||||
if testCase.errMessage != "" {
|
||||
assert.EqualError(t, err, testCase.errMessage)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, testCase.rootNode, rootNode)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user