4 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
11 // Gocheck boilerplate
12 func Test(t *testing.T) {
16 var _ = Suite(&ServerRequiredSuite{})
17 var _ = Suite(&UnitSuite{})
19 // Tests that require the Keep server running
20 type ServerRequiredSuite struct{}
22 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
23 arvadostest.StartAPI()
24 arvadostest.StartKeep()
27 func (s *ServerRequiredSuite) SetUpTest(c *C) {
28 arvadostest.ResetEnv()
31 func (s *ServerRequiredSuite) TestMakeArvadosClientSecure(c *C) {
32 os.Setenv("ARVADOS_API_HOST_INSECURE", "")
33 kc, err := MakeArvadosClient()
34 c.Assert(err, Equals, nil)
35 c.Check(kc.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST"))
36 c.Check(kc.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN"))
37 c.Check(kc.ApiInsecure, Equals, false)
40 func (s *ServerRequiredSuite) TestMakeArvadosClientInsecure(c *C) {
41 os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
42 kc, err := MakeArvadosClient()
43 c.Assert(err, Equals, nil)
44 c.Check(kc.ApiInsecure, Equals, true)
45 c.Check(kc.ApiServer, Equals, os.Getenv("ARVADOS_API_HOST"))
46 c.Check(kc.ApiToken, Equals, os.Getenv("ARVADOS_API_TOKEN"))
47 c.Check(kc.Client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify, Equals, true)
50 func (s *ServerRequiredSuite) TestGetInvalidUUID(c *C) {
51 arv, err := MakeArvadosClient()
54 err = arv.Get("collections", "", nil, &getback)
55 c.Assert(err, Equals, ErrInvalidArgument)
56 c.Assert(len(getback), Equals, 0)
58 err = arv.Get("collections", "zebra-moose-unicorn", nil, &getback)
59 c.Assert(err, Equals, ErrInvalidArgument)
60 c.Assert(len(getback), Equals, 0)
62 err = arv.Get("collections", "acbd18db4cc2f85cedef654fccc4a4d8", nil, &getback)
63 c.Assert(err, Equals, ErrInvalidArgument)
64 c.Assert(len(getback), Equals, 0)
67 func (s *ServerRequiredSuite) TestGetValidUUID(c *C) {
68 arv, err := MakeArvadosClient()
71 err = arv.Get("collections", "zzzzz-4zz18-abcdeabcdeabcde", nil, &getback)
72 c.Assert(err, FitsTypeOf, APIServerError{})
73 c.Assert(err.(APIServerError).HttpStatusCode, Equals, http.StatusNotFound)
74 c.Assert(len(getback), Equals, 0)
76 err = arv.Get("collections", "acbd18db4cc2f85cedef654fccc4a4d8+3", nil, &getback)
77 c.Assert(err, FitsTypeOf, APIServerError{})
78 c.Assert(err.(APIServerError).HttpStatusCode, Equals, http.StatusNotFound)
79 c.Assert(len(getback), Equals, 0)
82 func (s *ServerRequiredSuite) TestInvalidResourceType(c *C) {
83 arv, err := MakeArvadosClient()
86 err = arv.Get("unicorns", "zzzzz-zebra-unicorn7unicorn", nil, &getback)
87 c.Assert(err, FitsTypeOf, APIServerError{})
88 c.Assert(err.(APIServerError).HttpStatusCode, Equals, http.StatusNotFound)
89 c.Assert(len(getback), Equals, 0)
91 err = arv.Update("unicorns", "zzzzz-zebra-unicorn7unicorn", nil, &getback)
92 c.Assert(err, FitsTypeOf, APIServerError{})
93 c.Assert(err.(APIServerError).HttpStatusCode, Equals, http.StatusNotFound)
94 c.Assert(len(getback), Equals, 0)
96 err = arv.List("unicorns", nil, &getback)
97 c.Assert(err, FitsTypeOf, APIServerError{})
98 c.Assert(err.(APIServerError).HttpStatusCode, Equals, http.StatusNotFound)
99 c.Assert(len(getback), Equals, 0)
102 func (s *ServerRequiredSuite) TestCreatePipelineTemplate(c *C) {
103 arv, err := MakeArvadosClient()
105 getback := make(Dict)
106 err = arv.Create("pipeline_templates",
107 Dict{"pipeline_template": Dict{
110 "c1": map[string]string{"script": "script1"},
111 "c2": map[string]string{"script": "script2"}}}},
113 c.Assert(err, Equals, nil)
114 c.Assert(getback["name"], Equals, "tmp")
115 c.Assert(getback["components"].(map[string]interface{})["c2"].(map[string]interface{})["script"], Equals, "script2")
117 uuid := getback["uuid"].(string)
120 err = arv.Get("pipeline_templates", uuid, nil, &getback)
121 c.Assert(err, Equals, nil)
122 c.Assert(getback["name"], Equals, "tmp")
123 c.Assert(getback["components"].(map[string]interface{})["c1"].(map[string]interface{})["script"], Equals, "script1")
126 err = arv.Update("pipeline_templates", uuid,
128 "pipeline_template": Dict{"name": "tmp2"}},
130 c.Assert(err, Equals, nil)
131 c.Assert(getback["name"], Equals, "tmp2")
133 c.Assert(getback["uuid"].(string), Equals, uuid)
135 err = arv.Delete("pipeline_templates", uuid, nil, &getback)
136 c.Assert(err, Equals, nil)
137 c.Assert(getback["name"], Equals, "tmp2")
140 func (s *ServerRequiredSuite) TestErrorResponse(c *C) {
141 arv, _ := MakeArvadosClient()
143 getback := make(Dict)
146 err := arv.Create("logs",
147 Dict{"log": Dict{"bogus_attr": "foo"}},
149 c.Assert(err, ErrorMatches, "arvados API server error: .*")
150 c.Assert(err, ErrorMatches, ".*unknown attribute: bogus_attr.*")
151 c.Assert(err, FitsTypeOf, APIServerError{})
152 c.Assert(err.(APIServerError).HttpStatusCode, Equals, 422)
156 err := arv.Create("bogus",
157 Dict{"bogus": Dict{}},
159 c.Assert(err, ErrorMatches, "arvados API server error: .*")
160 c.Assert(err, ErrorMatches, ".*Path not found.*")
161 c.Assert(err, FitsTypeOf, APIServerError{})
162 c.Assert(err.(APIServerError).HttpStatusCode, Equals, 404)
166 func (s *ServerRequiredSuite) TestAPIDiscovery_Get_defaultCollectionReplication(c *C) {
167 arv, err := MakeArvadosClient()
168 value, err := arv.Discovery("defaultCollectionReplication")
170 c.Assert(value, NotNil)
173 func (s *ServerRequiredSuite) TestAPIDiscovery_Get_noSuchParameter(c *C) {
174 arv, err := MakeArvadosClient()
175 value, err := arv.Discovery("noSuchParameter")
176 c.Assert(err, NotNil)
177 c.Assert(value, IsNil)
180 type UnitSuite struct{}
182 func (s *UnitSuite) TestUUIDMatch(c *C) {
183 c.Assert(UUIDMatch("zzzzz-tpzed-000000000000000"), Equals, true)
184 c.Assert(UUIDMatch("zzzzz-zebra-000000000000000"), Equals, true)
185 c.Assert(UUIDMatch("00000-00000-zzzzzzzzzzzzzzz"), Equals, true)
186 c.Assert(UUIDMatch("ZEBRA-HORSE-AFRICANELEPHANT"), Equals, false)
187 c.Assert(UUIDMatch(" zzzzz-tpzed-000000000000000"), Equals, false)
188 c.Assert(UUIDMatch("d41d8cd98f00b204e9800998ecf8427e"), Equals, false)
189 c.Assert(UUIDMatch("d41d8cd98f00b204e9800998ecf8427e+0"), Equals, false)
190 c.Assert(UUIDMatch(""), Equals, false)
193 func (s *UnitSuite) TestPDHMatch(c *C) {
194 c.Assert(PDHMatch("zzzzz-tpzed-000000000000000"), Equals, false)
195 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e"), Equals, false)
196 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e+0"), Equals, true)
197 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e+12345"), Equals, true)
198 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e 12345"), Equals, false)
199 c.Assert(PDHMatch("D41D8CD98F00B204E9800998ECF8427E+12345"), Equals, false)
200 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e+12345 "), Equals, false)
201 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e+abcdef"), Equals, false)
202 c.Assert(PDHMatch("da39a3ee5e6b4b0d3255bfef95601890afd80709"), Equals, false)
203 c.Assert(PDHMatch("da39a3ee5e6b4b0d3255bfef95601890afd80709+0"), Equals, false)
204 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427+12345"), Equals, false)
205 c.Assert(PDHMatch("d41d8cd98f00b204e9800998ecf8427e+12345\n"), Equals, false)
206 c.Assert(PDHMatch("+12345"), Equals, false)
207 c.Assert(PDHMatch(""), Equals, false)