[19.03 backport] Harden TestClientWithRequestTimeout
| ... | ... |
@@ -2,7 +2,6 @@ package plugins // import "github.com/docker/docker/pkg/plugins" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
- "context" |
|
| 6 | 5 |
"encoding/json" |
| 7 | 6 |
"io" |
| 8 | 7 |
"net/http" |
| ... | ... |
@@ -237,6 +236,10 @@ func TestClientSendFile(t *testing.T) {
|
| 237 | 237 |
} |
| 238 | 238 |
|
| 239 | 239 |
func TestClientWithRequestTimeout(t *testing.T) {
|
| 240 |
+ type timeoutError interface {
|
|
| 241 |
+ Timeout() bool |
|
| 242 |
+ } |
|
| 243 |
+ |
|
| 240 | 244 |
timeout := 1 * time.Millisecond |
| 241 | 245 |
testHandler := func(w http.ResponseWriter, r *http.Request) {
|
| 242 | 246 |
time.Sleep(timeout + 1*time.Millisecond) |
| ... | ... |
@@ -251,12 +254,8 @@ func TestClientWithRequestTimeout(t *testing.T) {
|
| 251 | 251 |
assert.Assert(t, is.ErrorContains(err, ""), "expected error") |
| 252 | 252 |
|
| 253 | 253 |
err = errors.Cause(err) |
| 254 |
- |
|
| 255 |
- switch e := err.(type) {
|
|
| 256 |
- case *url.Error: |
|
| 257 |
- err = e.Err |
|
| 258 |
- } |
|
| 259 |
- assert.DeepEqual(t, context.DeadlineExceeded, err) |
|
| 254 |
+ assert.ErrorType(t, err, (*timeoutError)(nil)) |
|
| 255 |
+ assert.Equal(t, err.(timeoutError).Timeout(), true) |
|
| 260 | 256 |
} |
| 261 | 257 |
|
| 262 | 258 |
type testRequestWrapper struct {
|