17755: Merge branch 'main' into 17755-add-singularity-to-compute-image
[arvados.git] / services / keepproxy / keepproxy_test.go
index c49fbe0bb368b90733f985990acadb651323f7fe..052109bf29b925af9ef8945274ce099c96e9f112 100644 (file)
@@ -7,7 +7,6 @@ package main
 import (
        "bytes"
        "crypto/md5"
-       "errors"
        "fmt"
        "io/ioutil"
        "math/rand"
@@ -77,7 +76,6 @@ func closeListener() {
 }
 
 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        arvadostest.StartKeep(2, false)
 }
 
@@ -87,11 +85,9 @@ func (s *ServerRequiredSuite) SetUpTest(c *C) {
 
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(2)
-       arvadostest.StopAPI()
 }
 
 func (s *ServerRequiredConfigYmlSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        // config.yml defines 4 keepstores
        arvadostest.StartKeep(4, false)
 }
@@ -102,11 +98,9 @@ func (s *ServerRequiredConfigYmlSuite) SetUpTest(c *C) {
 
 func (s *ServerRequiredConfigYmlSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(4)
-       arvadostest.StopAPI()
 }
 
 func (s *NoKeepServerSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        // We need API to have some keep services listed, but the
        // services themselves should be unresponsive.
        arvadostest.StartKeep(2, false)
@@ -117,10 +111,6 @@ func (s *NoKeepServerSuite) SetUpTest(c *C) {
        arvadostest.ResetEnv()
 }
 
-func (s *NoKeepServerSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
-}
-
 func runProxy(c *C, bogusClientToken bool, loadKeepstoresFromConfig bool, kp *arvados.UploadDownloadRolePermissions) (*keepclient.KeepClient, *bytes.Buffer) {
        cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
        c.Assert(err, Equals, nil)
@@ -265,12 +255,16 @@ func (s *ServerRequiredSuite) TestDesiredReplicas(c *C) {
        content := []byte("TestDesiredReplicas")
        hash := fmt.Sprintf("%x", md5.Sum(content))
 
-       for _, kc.Want_replicas = range []int{0, 1, 2} {
+       for _, kc.Want_replicas = range []int{0, 1, 2, 3} {
                locator, rep, err := kc.PutB(content)
-               c.Check(err, Equals, nil)
-               c.Check(rep, Equals, kc.Want_replicas)
-               if rep > 0 {
-                       c.Check(locator, Matches, fmt.Sprintf(`^%s\+%d(\+.+)?$`, hash, len(content)))
+               if kc.Want_replicas < 3 {
+                       c.Check(err, Equals, nil)
+                       c.Check(rep, Equals, kc.Want_replicas)
+                       if rep > 0 {
+                               c.Check(locator, Matches, fmt.Sprintf(`^%s\+%d(\+.+)?$`, hash, len(content)))
+                       }
+               } else {
+                       c.Check(err, ErrorMatches, ".*503.*")
                }
        }
 }
@@ -438,7 +432,7 @@ func (s *ServerRequiredSuite) TestPutAskGetForbidden(c *C) {
        hash2, rep, err := kc.PutB([]byte("bar"))
        c.Check(hash2, Equals, "")
        c.Check(rep, Equals, 0)
-       c.Check(err, FitsTypeOf, keepclient.InsufficientReplicasError(errors.New("")))
+       c.Check(err, FitsTypeOf, keepclient.InsufficientReplicasError{})
 
        blocklen, _, err := kc.Ask(hash)
        c.Check(err, FitsTypeOf, &keepclient.ErrNotFound{})
@@ -491,7 +485,7 @@ func testPermission(c *C, admin bool, perm arvados.UploadDownloadPermission) {
                } else {
                        c.Check(hash2, Equals, "")
                        c.Check(rep, Equals, 0)
-                       c.Check(err, FitsTypeOf, keepclient.InsufficientReplicasError(errors.New("")))
+                       c.Check(err, FitsTypeOf, keepclient.InsufficientReplicasError{})
                }
                logbuf.Reset()
        }