X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b7e1d12d3f0e22280b9aeb23ca445a86a5ed6b7c..d43d242b4e55533c08f9526d88b0e3a9d8fd120e:/sdk/go/keepclient/keepclient_test.go diff --git a/sdk/go/keepclient/keepclient_test.go b/sdk/go/keepclient/keepclient_test.go index ed2cee6451..fe133fe2cb 100644 --- a/sdk/go/keepclient/keepclient_test.go +++ b/sdk/go/keepclient/keepclient_test.go @@ -41,8 +41,16 @@ type ServerRequiredSuite struct{} // Standalone tests type StandaloneSuite struct{} +var origHOME = os.Getenv("HOME") + func (s *StandaloneSuite) SetUpTest(c *C) { RefreshServiceDiscovery() + // Prevent cache state from leaking between test cases + os.Setenv("HOME", c.MkDir()) +} + +func (s *StandaloneSuite) TearDownTest(c *C) { + os.Setenv("HOME", origHOME) } func pythonDir() string { @@ -56,19 +64,22 @@ func (s *ServerRequiredSuite) SetUpSuite(c *C) { func (s *ServerRequiredSuite) TearDownSuite(c *C) { arvadostest.StopKeep(2) + os.Setenv("HOME", origHOME) } func (s *ServerRequiredSuite) SetUpTest(c *C) { RefreshServiceDiscovery() + // Prevent cache state from leaking between test cases + os.Setenv("HOME", c.MkDir()) } func (s *ServerRequiredSuite) TestMakeKeepClient(c *C) { arv, err := arvadosclient.MakeArvadosClient() - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) kc, err := MakeKeepClient(arv) - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) c.Check(len(kc.LocalRoots()), Equals, 2) for _, root := range kc.LocalRoots() { c.Check(root, Matches, "http://localhost:\\d+") @@ -84,8 +95,7 @@ func (s *ServerRequiredSuite) TestDefaultStorageClasses(c *C) { c.Assert(cc, NotNil) c.Assert(cc.(map[string]interface{})["default"], NotNil) - kc, err := MakeKeepClient(arv) - c.Assert(err, IsNil) + kc := New(arv) c.Assert(kc.DefaultStorageClasses, DeepEquals, []string{"default"}) } @@ -130,7 +140,7 @@ func (sph *StubPutHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request sph.c.Check(req.Header.Get("X-Keep-Storage-Classes"), Equals, sph.expectStorageClass) } body, err := ioutil.ReadAll(req.Body) - sph.c.Check(err, Equals, nil) + sph.c.Check(err, IsNil) sph.c.Check(body, DeepEquals, []byte(sph.expectBody)) resp.Header().Set("X-Keep-Replicas-Stored", "1") if sph.returnStorageClasses != "" { @@ -253,6 +263,78 @@ func (s *StandaloneSuite) TestUploadWithStorageClasses(c *C) { } } +func (s *StandaloneSuite) TestPutWithoutStorageClassesClusterSupport(c *C) { + nServers := 5 + for _, trial := range []struct { + replicas int + clientClasses []string + putClasses []string + minRequests int + maxRequests int + success bool + }{ + // Talking to an older cluster (no default storage classes exported + // config) and no other additional storage classes requirements. + {1, nil, nil, 1, 1, true}, + {2, nil, nil, 2, 2, true}, + {3, nil, nil, 3, 3, true}, + {nServers*2 + 1, nil, nil, nServers, nServers, false}, + + {1, []string{"class1"}, nil, 1, 1, true}, + {2, []string{"class1"}, nil, 2, 2, true}, + {3, []string{"class1"}, nil, 3, 3, true}, + {1, []string{"class1", "class2"}, nil, 1, 1, true}, + {nServers*2 + 1, []string{"class1"}, nil, nServers, nServers, false}, + + {1, nil, []string{"class1"}, 1, 1, true}, + {2, nil, []string{"class1"}, 2, 2, true}, + {3, nil, []string{"class1"}, 3, 3, true}, + {1, nil, []string{"class1", "class2"}, 1, 1, true}, + {nServers*2 + 1, nil, []string{"class1"}, nServers, nServers, false}, + } { + c.Logf("%+v", trial) + st := &StubPutHandler{ + c: c, + expectPath: "acbd18db4cc2f85cedef654fccc4a4d8", + expectAPIToken: "abc123", + expectBody: "foo", + expectStorageClass: "*", + returnStorageClasses: "", // Simulate old cluster without SC keep support + handled: make(chan string, 100), + } + ks := RunSomeFakeKeepServers(st, nServers) + arv, _ := arvadosclient.MakeArvadosClient() + kc, _ := MakeKeepClient(arv) + kc.Want_replicas = trial.replicas + kc.StorageClasses = trial.clientClasses + kc.DefaultStorageClasses = nil // Simulate an old cluster without SC defaults + arv.ApiToken = "abc123" + localRoots := make(map[string]string) + writableLocalRoots := make(map[string]string) + for i, k := range ks { + localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url + writableLocalRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url + defer k.listener.Close() + } + kc.SetServiceRoots(localRoots, writableLocalRoots, nil) + + _, err := kc.BlockWrite(context.Background(), arvados.BlockWriteOptions{ + Data: []byte("foo"), + StorageClasses: trial.putClasses, + }) + if trial.success { + c.Check(err, IsNil) + } else { + c.Check(err, NotNil) + } + c.Check(len(st.handled) >= trial.minRequests, Equals, true, Commentf("len(st.handled)==%d, trial.minRequests==%d", len(st.handled), trial.minRequests)) + c.Check(len(st.handled) <= trial.maxRequests, Equals, true, Commentf("len(st.handled)==%d, trial.maxRequests==%d", len(st.handled), trial.maxRequests)) + if trial.clientClasses == nil && trial.putClasses == nil { + c.Check(st.requests[0].Header.Get("X-Keep-Storage-Classes"), Equals, "") + } + } +} + func (s *StandaloneSuite) TestPutWithStorageClasses(c *C) { nServers := 5 for _, trial := range []struct { @@ -282,20 +364,6 @@ func (s *StandaloneSuite) TestPutWithStorageClasses(c *C) { {1, []string{"class1"}, []string{"class404"}, nil, nServers, nServers, false}, {1, []string{"class1"}, []string{"class1", "class404"}, nil, nServers, nServers, false}, {1, []string{"class1"}, nil, []string{"class1", "class404"}, nServers, nServers, false}, - - // Talking to an older cluster (with no default storage classes advertising) - {1, nil, []string{"class1"}, nil, 1, 1, true}, - {2, nil, []string{"class1"}, nil, 1, 2, true}, - {3, nil, []string{"class1"}, nil, 2, 3, true}, - {1, nil, []string{"class1", "class2"}, nil, 1, 1, true}, - {3, nil, nil, []string{"class1"}, 2, 3, true}, - {1, nil, nil, []string{"class1", "class2"}, 1, 1, true}, - {1, nil, []string{"class404"}, []string{"class1", "class2"}, 1, 1, true}, - {1, nil, []string{"class1"}, []string{"class404", "class2"}, nServers, nServers, false}, - {nServers*2 + 1, []string{}, []string{"class1"}, nil, nServers, nServers, false}, - {1, nil, []string{"class404"}, nil, nServers, nServers, false}, - {1, nil, []string{"class1", "class404"}, nil, nServers, nServers, false}, - {1, nil, nil, []string{"class1", "class404"}, nServers, nServers, false}, } { c.Logf("%+v", trial) st := &StubPutHandler{ @@ -462,7 +530,7 @@ func (s *StandaloneSuite) TestPutB(c *C) { } func (s *StandaloneSuite) TestPutHR(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := &StubPutHandler{ c: c, @@ -561,7 +629,7 @@ func (s *StandaloneSuite) TestPutWithFail(c *C) { <-fh.handled - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(phash, Equals, "") c.Check(replicas, Equals, 2) @@ -640,7 +708,7 @@ func (sgh StubGetHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) } func (s *StandaloneSuite) TestGet(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := StubGetHandler{ c, @@ -658,19 +726,18 @@ func (s *StandaloneSuite) TestGet(c *C) { arv.ApiToken = "abc123" kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) - r, n, url2, err := kc.Get(hash) - defer r.Close() - c.Check(err, Equals, nil) + r, n, _, err := kc.Get(hash) + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(url2, Equals, fmt.Sprintf("%s/%s", ks.url, hash)) content, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + c.Check(err2, IsNil) c.Check(content, DeepEquals, []byte("foo")) + c.Check(r.Close(), IsNil) } func (s *StandaloneSuite) TestGet404(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := Error404Handler{make(chan string, 1)} @@ -683,11 +750,10 @@ func (s *StandaloneSuite) TestGet404(c *C) { arv.ApiToken = "abc123" kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) - r, n, url2, err := kc.Get(hash) + r, n, _, err := kc.Get(hash) c.Check(err, Equals, BlockNotFound) c.Check(n, Equals, int64(0)) - c.Check(url2, Equals, "") - c.Check(r, Equals, nil) + c.Check(r, IsNil) } func (s *StandaloneSuite) TestGetEmptyBlock(c *C) { @@ -702,18 +768,18 @@ func (s *StandaloneSuite) TestGetEmptyBlock(c *C) { arv.ApiToken = "abc123" kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) - r, n, url2, err := kc.Get("d41d8cd98f00b204e9800998ecf8427e+0") + r, n, _, err := kc.Get("d41d8cd98f00b204e9800998ecf8427e+0") c.Check(err, IsNil) c.Check(n, Equals, int64(0)) - c.Check(url2, Equals, "") c.Assert(r, NotNil) buf, err := ioutil.ReadAll(r) c.Check(err, IsNil) c.Check(buf, DeepEquals, []byte{}) + c.Check(r.Close(), IsNil) } func (s *StandaloneSuite) TestGetFail(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := FailHandler{make(chan string, 1)} @@ -727,18 +793,18 @@ func (s *StandaloneSuite) TestGetFail(c *C) { kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) kc.Retries = 0 - r, n, url2, err := kc.Get(hash) + r, n, _, err := kc.Get(hash) errNotFound, _ := err.(*ErrNotFound) - c.Check(errNotFound, NotNil) - c.Check(strings.Contains(errNotFound.Error(), "HTTP 500"), Equals, true) - c.Check(errNotFound.Temporary(), Equals, true) + if c.Check(errNotFound, NotNil) { + c.Check(strings.Contains(errNotFound.Error(), "HTTP 500"), Equals, true) + c.Check(errNotFound.Temporary(), Equals, true) + } c.Check(n, Equals, int64(0)) - c.Check(url2, Equals, "") - c.Check(r, Equals, nil) + c.Check(r, IsNil) } func (s *StandaloneSuite) TestGetFailRetry(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := &FailThenSucceedHandler{ handled: make(chan string, 1), @@ -758,15 +824,14 @@ func (s *StandaloneSuite) TestGetFailRetry(c *C) { arv.ApiToken = "abc123" kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) - r, n, url2, err := kc.Get(hash) - defer r.Close() - c.Check(err, Equals, nil) + r, n, _, err := kc.Get(hash) + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(url2, Equals, fmt.Sprintf("%s/%s", ks.url, hash)) - content, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + content, err := ioutil.ReadAll(r) + c.Check(err, IsNil) c.Check(content, DeepEquals, []byte("foo")) + c.Check(r.Close(), IsNil) c.Logf("%q", st.reqIDs) c.Assert(len(st.reqIDs) > 1, Equals, true) @@ -777,7 +842,7 @@ func (s *StandaloneSuite) TestGetFailRetry(c *C) { } func (s *StandaloneSuite) TestGetNetError(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) arv, err := arvadosclient.MakeArvadosClient() c.Check(err, IsNil) @@ -785,19 +850,19 @@ func (s *StandaloneSuite) TestGetNetError(c *C) { arv.ApiToken = "abc123" kc.SetServiceRoots(map[string]string{"x": "http://localhost:62222"}, nil, nil) - r, n, url2, err := kc.Get(hash) + r, n, _, err := kc.Get(hash) errNotFound, _ := err.(*ErrNotFound) - c.Check(errNotFound, NotNil) - c.Check(strings.Contains(errNotFound.Error(), "connection refused"), Equals, true) - c.Check(errNotFound.Temporary(), Equals, true) + if c.Check(errNotFound, NotNil) { + c.Check(strings.Contains(errNotFound.Error(), "connection refused"), Equals, true) + c.Check(errNotFound.Temporary(), Equals, true) + } c.Check(n, Equals, int64(0)) - c.Check(url2, Equals, "") - c.Check(r, Equals, nil) + c.Check(r, IsNil) } func (s *StandaloneSuite) TestGetWithServiceHint(c *C) { uuid := "zzzzz-bi6l4-123451234512345" - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) // This one shouldn't be used: ks0 := RunFakeKeepServer(StubGetHandler{ @@ -825,22 +890,21 @@ func (s *StandaloneSuite) TestGetWithServiceHint(c *C) { nil, map[string]string{uuid: ks.url}) - r, n, uri, err := kc.Get(hash + "+K@" + uuid) - defer r.Close() - c.Check(err, Equals, nil) + r, n, _, err := kc.Get(hash + "+K@" + uuid) + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(uri, Equals, fmt.Sprintf("%s/%s", ks.url, hash+"+K@"+uuid)) content, err := ioutil.ReadAll(r) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(content, DeepEquals, []byte("foo")) + c.Check(r.Close(), IsNil) } // Use a service hint to fetch from a local disk service, overriding // rendezvous probe order. func (s *StandaloneSuite) TestGetWithLocalServiceHint(c *C) { uuid := "zzzzz-bi6l4-zzzzzzzzzzzzzzz" - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) // This one shouldn't be used, although it appears first in // rendezvous probe order: @@ -848,8 +912,8 @@ func (s *StandaloneSuite) TestGetWithLocalServiceHint(c *C) { c, "error if used", "abc123", - http.StatusOK, - []byte("foo")}) + http.StatusBadGateway, + nil}) defer ks0.listener.Close() // This one should be used: ks := RunFakeKeepServer(StubGetHandler{ @@ -878,20 +942,19 @@ func (s *StandaloneSuite) TestGetWithLocalServiceHint(c *C) { uuid: ks.url}, ) - r, n, uri, err := kc.Get(hash + "+K@" + uuid) - defer r.Close() - c.Check(err, Equals, nil) + r, n, _, err := kc.Get(hash + "+K@" + uuid) + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(uri, Equals, fmt.Sprintf("%s/%s", ks.url, hash+"+K@"+uuid)) content, err := ioutil.ReadAll(r) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(content, DeepEquals, []byte("foo")) + c.Check(r.Close(), IsNil) } func (s *StandaloneSuite) TestGetWithServiceHintFailoverToLocals(c *C) { uuid := "zzzzz-bi6l4-123451234512345" - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) ksLocal := RunFakeKeepServer(StubGetHandler{ c, @@ -917,15 +980,14 @@ func (s *StandaloneSuite) TestGetWithServiceHintFailoverToLocals(c *C) { nil, map[string]string{uuid: ksGateway.url}) - r, n, uri, err := kc.Get(hash + "+K@" + uuid) - c.Assert(err, Equals, nil) - defer r.Close() + r, n, _, err := kc.Get(hash + "+K@" + uuid) + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(uri, Equals, fmt.Sprintf("%s/%s", ksLocal.url, hash+"+K@"+uuid)) content, err := ioutil.ReadAll(r) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(content, DeepEquals, []byte("foo")) + c.Check(r.Close(), IsNil) } type BarHandler struct { @@ -938,8 +1000,8 @@ func (h BarHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { } func (s *StandaloneSuite) TestChecksum(c *C) { - foohash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) - barhash := fmt.Sprintf("%x", md5.Sum([]byte("bar"))) + foohash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) + barhash := fmt.Sprintf("%x+3", md5.Sum([]byte("bar"))) st := BarHandler{make(chan string, 1)} @@ -953,25 +1015,36 @@ func (s *StandaloneSuite) TestChecksum(c *C) { kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) r, n, _, err := kc.Get(barhash) - c.Check(err, IsNil) - _, err = ioutil.ReadAll(r) - c.Check(n, Equals, int64(3)) - c.Check(err, Equals, nil) + if c.Check(err, IsNil) { + _, err = ioutil.ReadAll(r) + c.Check(n, Equals, int64(3)) + c.Check(err, IsNil) + } - <-st.handled + select { + case <-st.handled: + case <-time.After(time.Second): + c.Fatal("timed out") + } r, n, _, err = kc.Get(foohash) - c.Check(err, IsNil) - _, err = ioutil.ReadAll(r) - c.Check(n, Equals, int64(3)) + if err == nil { + buf, readerr := ioutil.ReadAll(r) + c.Logf("%q", buf) + err = readerr + } c.Check(err, Equals, BadChecksum) - <-st.handled + select { + case <-st.handled: + case <-time.After(time.Second): + c.Fatal("timed out") + } } func (s *StandaloneSuite) TestGetWithFailures(c *C) { content := []byte("waz") - hash := fmt.Sprintf("%x", md5.Sum(content)) + hash := fmt.Sprintf("%x+3", md5.Sum(content)) fh := Error404Handler{ make(chan string, 4)} @@ -1015,16 +1088,20 @@ func (s *StandaloneSuite) TestGetWithFailures(c *C) { // an example that passes this Assert.) c.Assert(NewRootSorter(localRoots, hash).GetSortedRoots()[0], Not(Equals), ks1[0].url) - r, n, url2, err := kc.Get(hash) + r, n, _, err := kc.Get(hash) - <-fh.handled - c.Check(err, Equals, nil) + select { + case <-fh.handled: + case <-time.After(time.Second): + c.Fatal("timed out") + } + c.Assert(err, IsNil) c.Check(n, Equals, int64(3)) - c.Check(url2, Equals, fmt.Sprintf("%s/%s", ks1[0].url, hash)) readContent, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + c.Check(err2, IsNil) c.Check(readContent, DeepEquals, content) + c.Check(r.Close(), IsNil) } func (s *ServerRequiredSuite) TestPutGetHead(c *C) { @@ -1033,9 +1110,9 @@ func (s *ServerRequiredSuite) TestPutGetHead(c *C) { arv, err := arvadosclient.MakeArvadosClient() c.Check(err, IsNil) kc, err := MakeKeepClient(arv) - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) - hash := fmt.Sprintf("%x", md5.Sum(content)) + hash := fmt.Sprintf("%x+%d", md5.Sum(content), len(content)) { n, _, err := kc.Ask(hash) @@ -1044,29 +1121,32 @@ func (s *ServerRequiredSuite) TestPutGetHead(c *C) { } { hash2, replicas, err := kc.PutB(content) - c.Check(hash2, Matches, fmt.Sprintf(`%s\+%d\b.*`, hash, len(content))) + c.Check(err, IsNil) + c.Check(hash2, Matches, `\Q`+hash+`\E\b.*`) c.Check(replicas, Equals, 2) - c.Check(err, Equals, nil) } { - r, n, url2, err := kc.Get(hash) - c.Check(err, Equals, nil) + r, n, _, err := kc.Get(hash) + c.Check(err, IsNil) c.Check(n, Equals, int64(len(content))) - c.Check(url2, Matches, fmt.Sprintf("http://localhost:\\d+/%s", hash)) - - readContent, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) - c.Check(readContent, DeepEquals, content) + if c.Check(r, NotNil) { + readContent, err := ioutil.ReadAll(r) + c.Check(err, IsNil) + if c.Check(len(readContent), Equals, len(content)) { + c.Check(readContent, DeepEquals, content) + } + c.Check(r.Close(), IsNil) + } } { n, url2, err := kc.Ask(hash) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(n, Equals, int64(len(content))) - c.Check(url2, Matches, fmt.Sprintf("http://localhost:\\d+/%s", hash)) + c.Check(url2, Matches, "http://localhost:\\d+/\\Q"+hash+"\\E") } { loc, err := kc.LocalLocator(hash) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Assert(len(loc) >= 32, Equals, true) c.Check(loc[:32], Equals, hash[:32]) } @@ -1113,7 +1193,7 @@ func (s *StandaloneSuite) TestPutProxy(c *C) { _, replicas, err := kc.PutB([]byte("foo")) <-st.handled - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(replicas, Equals, 2) } @@ -1147,7 +1227,7 @@ func (s *StandaloneSuite) TestPutProxyInsufficientReplicas(c *C) { func (s *StandaloneSuite) TestMakeLocator(c *C) { l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce+3+Aabcde@12345678") - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce") c.Check(l.Size, Equals, 3) c.Check(l.Hints, DeepEquals, []string{"3", "Aabcde@12345678"}) @@ -1155,7 +1235,7 @@ func (s *StandaloneSuite) TestMakeLocator(c *C) { func (s *StandaloneSuite) TestMakeLocatorNoHints(c *C) { l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce") - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce") c.Check(l.Size, Equals, -1) c.Check(l.Hints, DeepEquals, []string{}) @@ -1163,7 +1243,7 @@ func (s *StandaloneSuite) TestMakeLocatorNoHints(c *C) { func (s *StandaloneSuite) TestMakeLocatorNoSizeHint(c *C) { l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce+Aabcde@12345678") - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce") c.Check(l.Size, Equals, -1) c.Check(l.Hints, DeepEquals, []string{"Aabcde@12345678"}) @@ -1172,7 +1252,7 @@ func (s *StandaloneSuite) TestMakeLocatorNoSizeHint(c *C) { func (s *StandaloneSuite) TestMakeLocatorPreservesUnrecognizedHints(c *C) { str := "91f372a266fe2bf2823cb8ec7fda31ce+3+Unknown+Kzzzzz+Afoobar" l, err := MakeLocator(str) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce") c.Check(l.Size, Equals, 3) c.Check(l.Hints, DeepEquals, []string{"3", "Unknown", "Kzzzzz", "Afoobar"}) @@ -1278,14 +1358,14 @@ func (h StubGetIndexHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reque } func (s *StandaloneSuite) TestGetIndexWithNoPrefix(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := StubGetIndexHandler{ c, "/index", "abc123", http.StatusOK, - []byte(hash + "+3 1443559274\n\n")} + []byte(hash + " 1443559274\n\n")} ks := RunFakeKeepServer(st) defer ks.listener.Close() @@ -1301,19 +1381,19 @@ func (s *StandaloneSuite) TestGetIndexWithNoPrefix(c *C) { c.Check(err, IsNil) content, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + c.Check(err2, IsNil) c.Check(content, DeepEquals, st.body[0:len(st.body)-1]) } func (s *StandaloneSuite) TestGetIndexWithPrefix(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := StubGetIndexHandler{ c, "/index/" + hash[0:3], "abc123", http.StatusOK, - []byte(hash + "+3 1443559274\n\n")} + []byte(hash + " 1443559274\n\n")} ks := RunFakeKeepServer(st) defer ks.listener.Close() @@ -1325,15 +1405,15 @@ func (s *StandaloneSuite) TestGetIndexWithPrefix(c *C) { kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) r, err := kc.GetIndex("x", hash[0:3]) - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) content, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + c.Check(err2, IsNil) c.Check(content, DeepEquals, st.body[0:len(st.body)-1]) } func (s *StandaloneSuite) TestGetIndexIncomplete(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := StubGetIndexHandler{ c, @@ -1356,7 +1436,7 @@ func (s *StandaloneSuite) TestGetIndexIncomplete(c *C) { } func (s *StandaloneSuite) TestGetIndexWithNoSuchServer(c *C) { - hash := fmt.Sprintf("%x", md5.Sum([]byte("foo"))) + hash := fmt.Sprintf("%x+3", md5.Sum([]byte("foo"))) st := StubGetIndexHandler{ c, @@ -1396,10 +1476,10 @@ func (s *StandaloneSuite) TestGetIndexWithNoSuchPrefix(c *C) { kc.SetServiceRoots(map[string]string{"x": ks.url}, nil, nil) r, err := kc.GetIndex("x", "abcd") - c.Check(err, Equals, nil) + c.Check(err, IsNil) content, err2 := ioutil.ReadAll(r) - c.Check(err2, Equals, nil) + c.Check(err2, IsNil) c.Check(content, DeepEquals, st.body[0:len(st.body)-1]) } @@ -1437,14 +1517,14 @@ func (s *StandaloneSuite) TestPutBRetry(c *C) { hash, replicas, err := kc.PutB([]byte("foo")) - c.Check(err, Equals, nil) + c.Check(err, IsNil) c.Check(hash, Equals, "") c.Check(replicas, Equals, 2) } func (s *ServerRequiredSuite) TestMakeKeepClientWithNonDiskTypeService(c *C) { arv, err := arvadosclient.MakeArvadosClient() - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) // Add an additional "testblobstore" keepservice blobKeepService := make(arvadosclient.Dict) @@ -1454,13 +1534,13 @@ func (s *ServerRequiredSuite) TestMakeKeepClientWithNonDiskTypeService(c *C) { "service_port": "21321", "service_type": "testblobstore"}}, &blobKeepService) - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) defer func() { arv.Delete("keep_services", blobKeepService["uuid"].(string), nil, nil) }() RefreshServiceDiscovery() // Make a keepclient and ensure that the testblobstore is included kc, err := MakeKeepClient(arv) - c.Assert(err, Equals, nil) + c.Assert(err, IsNil) // verify kc.LocalRoots c.Check(len(kc.LocalRoots()), Equals, 3)