Merge branch '21666-provision-test-improvement'
[arvados.git] / services / keepproxy / keepproxy_test.go
index 2eaea278162c9c4d2fb308b30d27b38e8ea5b639..ea8c9ba6ca4cfb6c1ec0b6e5f6734bc0aee7bef4 100644 (file)
@@ -32,8 +32,8 @@ import (
        . "gopkg.in/check.v1"
 )
 
-// Gocheck boilerplate
 func Test(t *testing.T) {
+       keepclient.DefaultRetryDelay = time.Millisecond
        TestingT(t)
 }
 
@@ -142,6 +142,7 @@ func runProxy(c *C, bogusClientToken bool, loadKeepstoresFromConfig bool, kp *ar
                arv.ApiToken = "bogus-token"
        }
        kc := keepclient.New(arv)
+       kc.DiskCacheSize = keepclient.DiskCacheDisabled
        sr := map[string]string{
                TestProxyUUID: "http://" + srv.Addr,
        }
@@ -345,7 +346,7 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
        }
 
        {
-               reader, _, _, err := kc.Get(hash)
+               reader, _, _, err := kc.Get(hash + "+3")
                c.Check(reader, Equals, nil)
                c.Check(err, Equals, keepclient.BlockNotFound)
                c.Log("Finished Get (expected BlockNotFound)")
@@ -406,7 +407,7 @@ func (s *ServerRequiredSuite) TestPutAskGet(c *C) {
 
        {
                reader, blocklen, _, err := kc.Get("d41d8cd98f00b204e9800998ecf8427e")
-               c.Assert(err, Equals, nil)
+               c.Assert(err, IsNil)
                all, err := ioutil.ReadAll(reader)
                c.Check(err, IsNil)
                c.Check(all, DeepEquals, []byte(""))
@@ -557,14 +558,14 @@ func (s *ServerRequiredSuite) TestCorsHeaders(c *C) {
                body, err := ioutil.ReadAll(resp.Body)
                c.Check(err, IsNil)
                c.Check(string(body), Equals, "")
-               c.Check(resp.Header.Get("Access-Control-Allow-Methods"), Equals, "GET, HEAD, POST, PUT, OPTIONS")
+               c.Check(resp.Header.Get("Access-Control-Allow-Methods"), Equals, "GET, HEAD, PUT, OPTIONS, POST")
                c.Check(resp.Header.Get("Access-Control-Allow-Origin"), Equals, "*")
        }
 
        {
                resp, err := http.Get(fmt.Sprintf("http://%s/%x+3", srv.Addr, md5.Sum([]byte("foo"))))
                c.Check(err, Equals, nil)
-               c.Check(resp.Header.Get("Access-Control-Allow-Headers"), Equals, "Authorization, Content-Length, Content-Type, X-Keep-Desired-Replicas")
+               c.Check(resp.Header.Get("Access-Control-Allow-Headers"), Equals, "Authorization, Content-Length, Content-Type, X-Keep-Desired-Replicas, X-Keep-Signature, X-Keep-Storage-Classes")
                c.Check(resp.Header.Get("Access-Control-Allow-Origin"), Equals, "*")
        }
 }
@@ -607,22 +608,22 @@ func (s *ServerRequiredSuite) TestStripHint(c *C) {
 }
 
 // Test GetIndex
-//   Put one block, with 2 replicas
-//   With no prefix (expect the block locator, twice)
-//   With an existing prefix (expect the block locator, twice)
-//   With a valid but non-existing prefix (expect "\n")
-//   With an invalid prefix (expect error)
+// - Put one block, with 2 replicas
+// - With no prefix (expect the block locator, twice)
+// - With an existing prefix (expect the block locator, twice)
+// - With a valid but non-existing prefix (expect "\n")
+// - With an invalid prefix (expect error)
 func (s *ServerRequiredSuite) TestGetIndex(c *C) {
        getIndexWorker(c, false)
 }
 
 // Test GetIndex
-//   Uses config.yml
-//   Put one block, with 2 replicas
-//   With no prefix (expect the block locator, twice)
-//   With an existing prefix (expect the block locator, twice)
-//   With a valid but non-existing prefix (expect "\n")
-//   With an invalid prefix (expect error)
+// - Uses config.yml
+// - Put one block, with 2 replicas
+// - With no prefix (expect the block locator, twice)
+// - With an existing prefix (expect the block locator, twice)
+// - With a valid but non-existing prefix (expect "\n")
+// - With an invalid prefix (expect error)
 func (s *ServerRequiredConfigYmlSuite) TestGetIndex(c *C) {
        getIndexWorker(c, true)
 }
@@ -640,7 +641,7 @@ func getIndexWorker(c *C, useConfig bool) {
        c.Check(rep, Equals, 2)
        c.Check(err, Equals, nil)
 
-       reader, blocklen, _, err := kc.Get(hash)
+       reader, blocklen, _, err := kc.Get(hash2)
        c.Assert(err, IsNil)
        c.Check(blocklen, Equals, int64(10))
        all, err := ioutil.ReadAll(reader)
@@ -695,7 +696,7 @@ func (s *ServerRequiredSuite) TestCollectionSharingToken(c *C) {
        defer srv.Close()
        hash, _, err := kc.PutB([]byte("shareddata"))
        c.Check(err, IsNil)
-       kc.Arvados.ApiToken = arvadostest.FooCollectionSharingToken
+       kc.Arvados.ApiToken = arvadostest.FooFileCollectionSharingToken
        rdr, _, _, err := kc.Get(hash)
        c.Assert(err, IsNil)
        data, err := ioutil.ReadAll(rdr)
@@ -782,10 +783,12 @@ func (s *NoKeepServerSuite) TestAskGetNoKeepServerError(c *C) {
                },
        } {
                err := f()
-               c.Assert(err, NotNil)
+               c.Check(err, NotNil)
                errNotFound, _ := err.(*keepclient.ErrNotFound)
-               c.Check(errNotFound.Temporary(), Equals, true)
-               c.Check(err, ErrorMatches, `.*HTTP 502.*`)
+               if c.Check(errNotFound, NotNil) {
+                       c.Check(errNotFound.Temporary(), Equals, true)
+                       c.Check(err, ErrorMatches, `.*HTTP 502.*`)
+               }
        }
 }