18947: Merge branch 'main'
[arvados.git] / lib / controller / router / router_test.go
index 639d2a28b4df5f647da44e9cd946863ff49d6abc..11b090a21495edb68312ff9856da9e3504872c81 100644 (file)
@@ -92,6 +92,12 @@ func (s *RouterSuite) TestOptions(c *check.C) {
                        shouldCall:  "CollectionList",
                        withOptions: arvados.ListOptions{Limit: -1},
                },
+               {
+                       method:      "GET",
+                       path:        "/arvados/v1/api_client_authorizations",
+                       shouldCall:  "APIClientAuthorizationList",
+                       withOptions: arvados.ListOptions{Limit: -1},
+               },
                {
                        method:      "GET",
                        path:        "/arvados/v1/collections?limit=123&offset=456&include_trash=true&include_old_versions=1",
@@ -125,7 +131,6 @@ func (s *RouterSuite) TestOptions(c *check.C) {
                        comment:     "form-encoded expression filter in query string",
                        method:      "GET",
                        path:        "/arvados/v1/collections?filters=[%22(foo<bar)%22]",
-                       header:      http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
                        shouldCall:  "CollectionList",
                        withOptions: arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"(foo<bar)", "=", true}}},
                },
@@ -147,6 +152,13 @@ func (s *RouterSuite) TestOptions(c *check.C) {
                        shouldCall:  "CollectionList",
                        withOptions: arvados.ListOptions{Limit: 2, Filters: []arvados.Filter{{"(foo<bar)", "=", true}, {"bar", "=", "baz"}}},
                },
+               {
+                       comment:     "json-encoded select param in query string",
+                       method:      "GET",
+                       path:        "/arvados/v1/collections/" + arvadostest.FooCollection + "?select=[%22portable_data_hash%22]",
+                       shouldCall:  "CollectionGet",
+                       withOptions: arvados.GetOptions{UUID: arvadostest.FooCollection, Select: []string{"portable_data_hash"}},
+               },
                {
                        method:       "PATCH",
                        path:         "/arvados/v1/collections",
@@ -373,10 +385,10 @@ func (s *RouterIntegrationSuite) TestFullTimestampsInResponse(c *check.C) {
 func (s *RouterIntegrationSuite) TestSelectParam(c *check.C) {
        uuid := arvadostest.QueuedContainerUUID
        token := arvadostest.ActiveTokenV2
+       // GET
        for _, sel := range [][]string{
                {"uuid", "command"},
                {"uuid", "command", "uuid"},
-               {"", "command", "uuid"},
        } {
                j, err := json.Marshal(sel)
                c.Assert(err, check.IsNil)
@@ -384,14 +396,32 @@ func (s *RouterIntegrationSuite) TestSelectParam(c *check.C) {
                c.Check(rr.Code, check.Equals, http.StatusOK)
 
                c.Check(resp["kind"], check.Equals, "arvados#container")
-               c.Check(resp["etag"], check.FitsTypeOf, "")
-               c.Check(resp["etag"], check.Not(check.Equals), "")
                c.Check(resp["uuid"], check.HasLen, 27)
                c.Check(resp["command"], check.HasLen, 2)
                c.Check(resp["mounts"], check.IsNil)
                _, hasMounts := resp["mounts"]
                c.Check(hasMounts, check.Equals, false)
        }
+       // POST & PUT
+       uuid = arvadostest.FooCollection
+       j, err := json.Marshal([]string{"uuid", "description"})
+       c.Assert(err, check.IsNil)
+       for _, method := range []string{"PUT", "POST"} {
+               desc := "Today is " + time.Now().String()
+               reqBody := "{\"description\":\"" + desc + "\"}"
+               var resp map[string]interface{}
+               var rr *httptest.ResponseRecorder
+               if method == "PUT" {
+                       _, rr, resp = doRequest(c, s.rtr, token, method, "/arvados/v1/collections/"+uuid+"?select="+string(j), nil, bytes.NewReader([]byte(reqBody)))
+               } else {
+                       _, rr, resp = doRequest(c, s.rtr, token, method, "/arvados/v1/collections?select="+string(j), nil, bytes.NewReader([]byte(reqBody)))
+               }
+               c.Check(rr.Code, check.Equals, http.StatusOK)
+               c.Check(resp["kind"], check.Equals, "arvados#collection")
+               c.Check(resp["uuid"], check.HasLen, 27)
+               c.Check(resp["description"], check.Equals, desc)
+               c.Check(resp["manifest_text"], check.IsNil)
+       }
 }
 
 func (s *RouterIntegrationSuite) TestHEAD(c *check.C) {