X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/898c73ef5179e3c0cdc088ca369500b40df23b89..e8d1a643cdbc3a5f4c0e5c745da58d9f7e1248d8:/sdk/go/arvadosclient/arvadosclient_test.go diff --git a/sdk/go/arvadosclient/arvadosclient_test.go b/sdk/go/arvadosclient/arvadosclient_test.go index bf8debe243..fc686ad637 100644 --- a/sdk/go/arvadosclient/arvadosclient_test.go +++ b/sdk/go/arvadosclient/arvadosclient_test.go @@ -1,14 +1,18 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package arvadosclient import ( "fmt" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" - . "gopkg.in/check.v1" "net" "net/http" "os" "testing" - "time" + + "git.arvados.org/arvados.git/sdk/go/arvadostest" + . "gopkg.in/check.v1" ) // Gocheck boilerplate @@ -29,31 +33,37 @@ func (s *ServerRequiredSuite) SetUpSuite(c *C) { RetryDelay = 0 } +func (s *ServerRequiredSuite) TearDownSuite(c *C) { + arvadostest.StopKeep(2) + arvadostest.StopAPI() +} + func (s *ServerRequiredSuite) SetUpTest(c *C) { arvadostest.ResetEnv() } func (s *ServerRequiredSuite) TestMakeArvadosClientSecure(c *C) { os.Setenv("ARVADOS_API_HOST_INSECURE", "") - kc, err := MakeArvadosClient() + ac, err := MakeArvadosClient() 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) + c.Check(ac.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST")) + c.Check(ac.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN")) + c.Check(ac.ApiInsecure, Equals, false) } func (s *ServerRequiredSuite) TestMakeArvadosClientInsecure(c *C) { os.Setenv("ARVADOS_API_HOST_INSECURE", "true") - kc, err := MakeArvadosClient() + ac, 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.Check(ac.ApiInsecure, Equals, true) + c.Check(ac.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST")) + c.Check(ac.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN")) + c.Check(ac.Client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, Equals, true) } func (s *ServerRequiredSuite) TestGetInvalidUUID(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("collections", "", nil, &getback) @@ -71,6 +81,7 @@ func (s *ServerRequiredSuite) TestGetInvalidUUID(c *C) { func (s *ServerRequiredSuite) TestGetValidUUID(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("collections", "zzzzz-4zz18-abcdeabcdeabcde", nil, &getback) @@ -86,6 +97,7 @@ func (s *ServerRequiredSuite) TestGetValidUUID(c *C) { func (s *ServerRequiredSuite) TestInvalidResourceType(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) getback := make(Dict) err = arv.Get("unicorns", "zzzzz-zebra-unicorn7unicorn", nil, &getback) @@ -104,55 +116,6 @@ func (s *ServerRequiredSuite) TestInvalidResourceType(c *C) { c.Assert(len(getback), Equals, 0) } -func (s *ServerRequiredSuite) TestCreatePipelineTemplate(c *C) { - arv, err := MakeArvadosClient() - - for _, idleConnections := range []bool{ - false, - true, - } { - if idleConnections { - arv.lastClosedIdlesAt = time.Now().Add(-time.Minute) - } else { - arv.lastClosedIdlesAt = time.Now() - } - - getback := make(Dict) - err = arv.Create("pipeline_templates", - Dict{"pipeline_template": Dict{ - "name": "tmp", - "components": Dict{ - "c1": map[string]string{"script": "script1"}, - "c2": map[string]string{"script": "script2"}}}}, - &getback) - c.Assert(err, Equals, nil) - c.Assert(getback["name"], Equals, "tmp") - c.Assert(getback["components"].(map[string]interface{})["c2"].(map[string]interface{})["script"], Equals, "script2") - - uuid := getback["uuid"].(string) - - getback = make(Dict) - err = arv.Get("pipeline_templates", uuid, nil, &getback) - c.Assert(err, Equals, nil) - c.Assert(getback["name"], Equals, "tmp") - c.Assert(getback["components"].(map[string]interface{})["c1"].(map[string]interface{})["script"], Equals, "script1") - - getback = make(Dict) - err = arv.Update("pipeline_templates", uuid, - Dict{ - "pipeline_template": Dict{"name": "tmp2"}}, - &getback) - c.Assert(err, Equals, nil) - c.Assert(getback["name"], Equals, "tmp2") - - c.Assert(getback["uuid"].(string), Equals, uuid) - getback = make(Dict) - err = arv.Delete("pipeline_templates", uuid, nil, &getback) - c.Assert(err, Equals, nil) - c.Assert(getback["name"], Equals, "tmp2") - } -} - func (s *ServerRequiredSuite) TestErrorResponse(c *C) { arv, _ := MakeArvadosClient() @@ -163,7 +126,7 @@ func (s *ServerRequiredSuite) TestErrorResponse(c *C) { 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, ErrorMatches, ".*unknown attribute(: | ')bogus_attr.*") c.Assert(err, FitsTypeOf, APIServerError{}) c.Assert(err.(APIServerError).HttpStatusCode, Equals, 422) } @@ -181,6 +144,7 @@ func (s *ServerRequiredSuite) TestErrorResponse(c *C) { func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) value, err := arv.Discovery("defaultCollectionReplication") c.Assert(err, IsNil) c.Assert(value, NotNil) @@ -188,6 +152,7 @@ func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication( func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) { arv, err := MakeArvadosClient() + c.Assert(err, IsNil) value, err := arv.Discovery("noSuchParameter") c.Assert(err, NotNil) c.Assert(value, IsNil) @@ -322,11 +287,16 @@ func (s *MockArvadosServerSuite) TestWithRetries(c *C) { { "get", 0, 401, []int{500, 401, 200}, []string{``, ``, `{"ok":"ok"}`}, }, - // Use nil responseBody to simulate error during request processing - // Even though retryable, the simulated error applies during reties also, and hence "get" also eventually fails in this test. + + // Response code -1 simulates an HTTP/network error + // (i.e., Do() returns an error; there is no HTTP + // response status code). + + // Succeed on second retry { "get", 0, 200, []int{-1, -1, 200}, []string{``, ``, `{"ok":"ok"}`}, }, + // "POST" is not safe to retry: fail after one error { "create", 0, -1, []int{-1, 200}, []string{``, `{"ok":"ok"}`}, },