mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-09 20:29:23 +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:
@@ -25,18 +25,15 @@ func Test_Client_AddPortMapping(t *testing.T) {
|
||||
assignedInternalPort uint16
|
||||
assignedExternalPort uint16
|
||||
assignedLifetime time.Duration
|
||||
err error
|
||||
errMessage string
|
||||
}{
|
||||
"lifetime_too_long": {
|
||||
lifetime: time.Duration(uint64(^uint32(0))+1) * time.Second,
|
||||
err: ErrLifetimeTooLong,
|
||||
errMessage: "lifetime is too long: 4294967296 seconds must at most 4294967295 seconds",
|
||||
},
|
||||
"protocol_unknown": {
|
||||
lifetime: time.Second,
|
||||
protocol: "xyz",
|
||||
err: ErrNetworkProtocolUnknown,
|
||||
errMessage: "network protocol is unknown: xyz",
|
||||
},
|
||||
"rpc_error": {
|
||||
@@ -48,7 +45,6 @@ func Test_Client_AddPortMapping(t *testing.T) {
|
||||
lifetime: 1200 * time.Second,
|
||||
initialConnectionDuration: time.Millisecond,
|
||||
exchanges: []udpExchange{{close: true}},
|
||||
err: ErrConnectionTimeout,
|
||||
errMessage: "executing remote procedure call: connection timeout: failed attempts: " +
|
||||
"read udp 127.0.0.1:[1-9][0-9]{0,4}->127.0.0.1:[1-9][0-9]{0,4}: i/o timeout \\(try 1\\)",
|
||||
},
|
||||
@@ -136,9 +132,6 @@ func Test_Client_AddPortMapping(t *testing.T) {
|
||||
assert.Equal(t, testCase.assignedExternalPort, assignedExternalPort)
|
||||
assert.Equal(t, testCase.assignedLifetime, assignedLifetime)
|
||||
if testCase.errMessage != "" {
|
||||
if testCase.err != nil {
|
||||
assert.ErrorIs(t, err, testCase.err)
|
||||
}
|
||||
assert.Regexp(t, "^"+testCase.errMessage+"$", err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user