Merge branch '17944-backend-vocabulary-validation-rebased' into main.
[arvados.git] / lib / controller / router / router_test.go
index 0330ec4252c9ad3ee8f461faf9ce7508c17bd3fc..7228956453d1d0c0f6dd460ef7638f19db76a459 100644 (file)
@@ -47,6 +47,7 @@ func (s *RouterSuite) SetUpTest(c *check.C) {
 func (s *RouterSuite) TestOptions(c *check.C) {
        token := arvadostest.ActiveToken
        for _, trial := range []struct {
+               comment      string // unparsed -- only used to help match test failures to trials
                method       string
                path         string
                header       http.Header
@@ -120,6 +121,38 @@ func (s *RouterSuite) TestOptions(c *check.C) {
                        shouldCall:  "CollectionList",
                        withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
                },
+               {
+                       comment:     "form-encoded expression filter in query string",
+                       method:      "GET",
+                       path:        "/arvados/v1/collections?filters=[%22(foo<bar)%22]",
+                       shouldCall:  "CollectionList",
+                       withOptions: arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"(foo<bar)", "=", true}}},
+               },
+               {
+                       comment:     "form-encoded expression filter in POST body",
+                       method:      "POST",
+                       path:        "/arvados/v1/collections",
+                       body:        "filters=[\"(foo<bar)\"]&_method=GET",
+                       header:      http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
+                       shouldCall:  "CollectionList",
+                       withOptions: arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"(foo<bar)", "=", true}}},
+               },
+               {
+                       comment:     "json-encoded expression filter in POST body",
+                       method:      "POST",
+                       path:        "/arvados/v1/collections?_method=GET",
+                       body:        `{"filters":["(foo<bar)",["bar","=","baz"]],"limit":2}`,
+                       header:      http.Header{"Content-Type": {"application/json"}},
+                       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",
@@ -139,21 +172,23 @@ func (s *RouterSuite) TestOptions(c *check.C) {
                // Reset calls captured in previous trial
                s.stub = arvadostest.APIStub{}
 
-               c.Logf("trial: %#v", trial)
+               c.Logf("trial: %+v", trial)
+               comment := check.Commentf("trial comment: %s", trial.comment)
+
                _, rr, _ := doRequest(c, s.rtr, token, trial.method, trial.path, trial.header, bytes.NewBufferString(trial.body))
                if trial.shouldStatus == 0 {
-                       c.Check(rr.Code, check.Equals, http.StatusOK)
+                       c.Check(rr.Code, check.Equals, http.StatusOK, comment)
                } else {
-                       c.Check(rr.Code, check.Equals, trial.shouldStatus)
+                       c.Check(rr.Code, check.Equals, trial.shouldStatus, comment)
                }
                calls := s.stub.Calls(nil)
                if trial.shouldCall == "" {
-                       c.Check(calls, check.HasLen, 0)
+                       c.Check(calls, check.HasLen, 0, comment)
                } else if len(calls) != 1 {
-                       c.Check(calls, check.HasLen, 1)
+                       c.Check(calls, check.HasLen, 1, comment)
                } else {
-                       c.Check(calls[0].Method, isMethodNamed, trial.shouldCall)
-                       c.Check(calls[0].Options, check.DeepEquals, trial.withOptions)
+                       c.Check(calls[0].Method, isMethodNamed, trial.shouldCall, comment)
+                       c.Check(calls[0].Options, check.DeepEquals, trial.withOptions, comment)
                }
        }
 }
@@ -347,7 +382,6 @@ func (s *RouterIntegrationSuite) TestSelectParam(c *check.C) {
        for _, sel := range [][]string{
                {"uuid", "command"},
                {"uuid", "command", "uuid"},
-               {"", "command", "uuid"},
        } {
                j, err := json.Marshal(sel)
                c.Assert(err, check.IsNil)
@@ -355,8 +389,6 @@ 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)