"net/url"
"sync"
"testing"
+ "testing/iotest"
)
type stubTransport struct {
return nil, fmt.Errorf("something awful happened")
}
+type timeoutTransport struct {
+ response []byte
+}
+
+func (stub *timeoutTransport) RoundTrip(req *http.Request) (*http.Response, error) {
+ return &http.Response{
+ Status: "200 OK",
+ StatusCode: 200,
+ Proto: "HTTP/1.1",
+ ProtoMajor: 1,
+ ProtoMinor: 1,
+ Request: req,
+ Body: ioutil.NopCloser(iotest.TimeoutReader(bytes.NewReader(stub.response))),
+ }, nil
+}
+
func TestCurrentUser(t *testing.T) {
t.Parallel()
stub := &stubTransport{
scanner := bufio.NewScanner(resp.Body)
sawEOF := false
for scanner.Scan() {
+ if scanner.Err() != nil {
+ // If we encounter a read error (timeout,
+ // connection failure), stop now and return it
+ // below, so it doesn't get masked by the
+ // ensuing "badly formatted response" error.
+ break
+ }
if sawEOF {
return nil, fmt.Errorf("Index response contained non-terminal blank line")
}
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package arvados
+
+import (
+ "net/http"
+
+ check "gopkg.in/check.v1"
+)
+
+var _ = check.Suite(&KeepServiceSuite{})
+
+type KeepServiceSuite struct{}
+
+func (*KeepServiceSuite) TestIndexTimeout(c *check.C) {
+ client := &Client{
+ Client: &http.Client{
+ Transport: &timeoutTransport{response: []byte("\n")},
+ },
+ APIHost: "zzzzz.arvadosapi.com",
+ AuthToken: "xyzzy",
+ }
+ _, err := (&KeepService{}).IndexMount(client, "fake", "")
+ c.Check(err, check.ErrorMatches, `.*timeout.*`)
+}