6235: Discovery() returns the requested value directly instead of a single-entry...
[arvados.git] / sdk / go / arvadosclient / arvadosclient_test.go
index bf9b4e31c41dbb5ba974e1da3b4d1dbb99cda7e3..6a9e13bb27a9d39e8af98e4cc5a22fbd01b29f97 100644 (file)
@@ -1,11 +1,10 @@
 package arvadosclient
 
 import (
-       "fmt"
+       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
        . "gopkg.in/check.v1"
        "net/http"
        "os"
-       "os/exec"
        "testing"
 )
 
@@ -19,47 +18,35 @@ var _ = Suite(&ServerRequiredSuite{})
 // Tests that require the Keep server running
 type ServerRequiredSuite struct{}
 
-func pythonDir() string {
-       cwd, _ := os.Getwd()
-       return fmt.Sprintf("%s/../../python/tests", cwd)
+func (s *ServerRequiredSuite) SetUpSuite(c *C) {
+       arvadostest.StartAPI()
+       arvadostest.StartKeep()
 }
 
-func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       os.Chdir(pythonDir())
-       if err := exec.Command("python", "run_test_server.py", "start").Run(); err != nil {
-               panic("'python run_test_server.py start' returned error")
-       }
-       if err := exec.Command("python", "run_test_server.py", "start_keep").Run(); err != nil {
-               panic("'python run_test_server.py start_keep' returned error")
-       }
+func (s *ServerRequiredSuite) SetUpTest(c *C) {
+       arvadostest.ResetEnv()
 }
 
-func (s *ServerRequiredSuite) TestMakeArvadosClient(c *C) {
-       os.Setenv("ARVADOS_API_HOST", "localhost:3000")
-       os.Setenv("ARVADOS_API_TOKEN", "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
+func (s *ServerRequiredSuite) TestMakeArvadosClientSecure(c *C) {
        os.Setenv("ARVADOS_API_HOST_INSECURE", "")
-
        kc, err := MakeArvadosClient()
-       c.Check(kc.ApiServer, Equals, "localhost:3000")
-       c.Check(kc.ApiToken, Equals, "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
+       c.Assert(err, Equals, nil)
+       c.Check(kc.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST"))
+       c.Check(kc.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN"))
        c.Check(kc.ApiInsecure, Equals, false)
+}
 
+func (s *ServerRequiredSuite) TestMakeArvadosClientInsecure(c *C) {
        os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
-
-       kc, err = MakeArvadosClient()
-       c.Check(kc.ApiServer, Equals, "localhost:3000")
-       c.Check(kc.ApiToken, Equals, "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
+       kc, err := MakeArvadosClient()
+       c.Assert(err, Equals, nil)
        c.Check(kc.ApiInsecure, Equals, true)
+       c.Check(kc.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST"))
+       c.Check(kc.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN"))
        c.Check(kc.Client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, Equals, true)
-
-       c.Assert(err, Equals, nil)
 }
 
 func (s *ServerRequiredSuite) TestCreatePipelineTemplate(c *C) {
-       os.Setenv("ARVADOS_API_HOST", "localhost:3000")
-       os.Setenv("ARVADOS_API_TOKEN", "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
-       os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
-
        arv, err := MakeArvadosClient()
 
        getback := make(Dict)
@@ -91,10 +78,6 @@ func (s *ServerRequiredSuite) TestCreatePipelineTemplate(c *C) {
 }
 
 func (s *ServerRequiredSuite) TestErrorResponse(c *C) {
-       os.Setenv("ARVADOS_API_HOST", "localhost:3000")
-       os.Setenv("ARVADOS_API_TOKEN", "4axaw8zxe0qm22wa6urpp5nskcne8z88cvbupv653y1njyi05h")
-       os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
-
        arv, _ := MakeArvadosClient()
 
        getback := make(Dict)
@@ -103,17 +86,33 @@ func (s *ServerRequiredSuite) TestErrorResponse(c *C) {
                err := arv.Create("logs",
                        Dict{"log": Dict{"bogus_attr": "foo"}},
                        &getback)
+               c.Assert(err, ErrorMatches, "arvados API server error: .*")
                c.Assert(err, ErrorMatches, ".*unknown attribute: bogus_attr.*")
-               c.Assert(err, FitsTypeOf, ArvadosApiError{})
-               c.Assert(err.(ArvadosApiError).HttpStatusCode, Equals, 422)
+               c.Assert(err, FitsTypeOf, APIServerError{})
+               c.Assert(err.(APIServerError).HttpStatusCode, Equals, 422)
        }
 
        {
                err := arv.Create("bogus",
                        Dict{"bogus": Dict{}},
                        &getback)
-               c.Assert(err, ErrorMatches, "Path not found")
-               c.Assert(err, FitsTypeOf, ArvadosApiError{})
-               c.Assert(err.(ArvadosApiError).HttpStatusCode, Equals, 404)
+               c.Assert(err, ErrorMatches, "arvados API server error: .*")
+               c.Assert(err, ErrorMatches, ".*Path not found.*")
+               c.Assert(err, FitsTypeOf, APIServerError{})
+               c.Assert(err.(APIServerError).HttpStatusCode, Equals, 404)
        }
 }
+
+func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication(c *C) {
+       arv, err := MakeArvadosClient()
+       value, err := arv.Discovery("defaultCollectionReplication")
+       c.Assert(err, IsNil)
+       c.Assert(value, NotNil)
+}
+
+func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) {
+       arv, err := MakeArvadosClient()
+       value, err := arv.Discovery("noSuchParameter")
+       c.Assert(err, NotNil)
+       c.Assert(value, IsNil)
+}