Explorar o código

Merge pull request #324 from thaJeztah/18.09_backport_harden_TestClientWithRequestTimeout

[18.09 backport] Harden TestClientWithRequestTimeout
Andrew Hsu %!s(int64=5) %!d(string=hai) anos
pai
achega
c88e4f77aa
Modificáronse 1 ficheiros con 6 adicións e 7 borrados
  1. 6 7
      pkg/plugins/client_test.go

+ 6 - 7
pkg/plugins/client_test.go

@@ -2,7 +2,6 @@ package plugins // import "github.com/docker/docker/pkg/plugins"
 
 
 import (
 import (
 	"bytes"
 	"bytes"
-	"context"
 	"encoding/json"
 	"encoding/json"
 	"io"
 	"io"
 	"net/http"
 	"net/http"
@@ -237,6 +236,10 @@ func TestClientSendFile(t *testing.T) {
 }
 }
 
 
 func TestClientWithRequestTimeout(t *testing.T) {
 func TestClientWithRequestTimeout(t *testing.T) {
+	type timeoutError interface {
+		Timeout() bool
+	}
+
 	timeout := 1 * time.Millisecond
 	timeout := 1 * time.Millisecond
 	testHandler := func(w http.ResponseWriter, r *http.Request) {
 	testHandler := func(w http.ResponseWriter, r *http.Request) {
 		time.Sleep(timeout + 1*time.Millisecond)
 		time.Sleep(timeout + 1*time.Millisecond)
@@ -251,12 +254,8 @@ func TestClientWithRequestTimeout(t *testing.T) {
 	assert.Assert(t, is.ErrorContains(err, ""), "expected error")
 	assert.Assert(t, is.ErrorContains(err, ""), "expected error")
 
 
 	err = errors.Cause(err)
 	err = errors.Cause(err)
-
-	switch e := err.(type) {
-	case *url.Error:
-		err = e.Err
-	}
-	assert.DeepEqual(t, context.DeadlineExceeded, err)
+	assert.ErrorType(t, err, (*timeoutError)(nil))
+	assert.Equal(t, err.(timeoutError).Timeout(), true)
 }
 }
 
 
 type testRequestWrapper struct {
 type testRequestWrapper struct {