|
@@ -5,12 +5,14 @@ import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "math/rand"
|
|
"net/http"
|
|
"net/http"
|
|
"strings"
|
|
"strings"
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types"
|
|
"gotest.tools/assert"
|
|
"gotest.tools/assert"
|
|
|
|
+ is "gotest.tools/assert/cmp"
|
|
)
|
|
)
|
|
|
|
|
|
// TestSetHostHeader should set fake host for local communications, set real host
|
|
// TestSetHostHeader should set fake host for local communications, set real host
|
|
@@ -87,3 +89,18 @@ func TestPlainTextError(t *testing.T) {
|
|
t.Fatalf("expected a Server Error, got %v", err)
|
|
t.Fatalf("expected a Server Error, got %v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func TestInfiniteError(t *testing.T) {
|
|
|
|
+ infinitR := rand.New(rand.NewSource(42))
|
|
|
|
+ client := &Client{
|
|
|
|
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
|
|
+ resp := &http.Response{StatusCode: http.StatusInternalServerError}
|
|
|
|
+ resp.Header = http.Header{}
|
|
|
|
+ resp.Body = ioutil.NopCloser(infinitR)
|
|
|
|
+ return resp, nil
|
|
|
|
+ }),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _, err := client.Ping(context.Background())
|
|
|
|
+ assert.Check(t, is.ErrorContains(err, "request returned Internal Server Error"))
|
|
|
|
+}
|