+ s.rtr.addRoutes()
+}
+
+func (s *RouterSuite) TestOptions(c *check.C) {
+ token := arvadostest.ActiveToken
+ for _, trial := range []struct {
+ method string
+ path string
+ header http.Header
+ body string
+ shouldStatus int // zero value means 200
+ shouldCall string
+ withOptions interface{}
+ }{
+ {
+ method: "GET",
+ path: "/arvados/v1/collections/" + arvadostest.FooCollection,
+ shouldCall: "CollectionGet",
+ withOptions: arvados.GetOptions{UUID: arvadostest.FooCollection},
+ },
+ {
+ method: "PUT",
+ path: "/arvados/v1/collections/" + arvadostest.FooCollection,
+ shouldCall: "CollectionUpdate",
+ withOptions: arvados.UpdateOptions{UUID: arvadostest.FooCollection},
+ },
+ {
+ method: "PATCH",
+ path: "/arvados/v1/collections/" + arvadostest.FooCollection,
+ shouldCall: "CollectionUpdate",
+ withOptions: arvados.UpdateOptions{UUID: arvadostest.FooCollection},
+ },
+ {
+ method: "DELETE",
+ path: "/arvados/v1/collections/" + arvadostest.FooCollection,
+ shouldCall: "CollectionDelete",
+ withOptions: arvados.DeleteOptions{UUID: arvadostest.FooCollection},
+ },
+ {
+ method: "POST",
+ path: "/arvados/v1/collections",
+ shouldCall: "CollectionCreate",
+ withOptions: arvados.CreateOptions{},
+ },
+ {
+ method: "GET",
+ path: "/arvados/v1/collections",
+ shouldCall: "CollectionList",
+ withOptions: arvados.ListOptions{Limit: -1},
+ },
+ {
+ method: "GET",
+ path: "/arvados/v1/collections?limit=123&offset=456&include_trash=true&include_old_versions=1",
+ shouldCall: "CollectionList",
+ withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
+ },
+ {
+ method: "POST",
+ path: "/arvados/v1/collections?limit=123&_method=GET",
+ body: `{"offset":456,"include_trash":true,"include_old_versions":true}`,
+ shouldCall: "CollectionList",
+ withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
+ },
+ {
+ method: "POST",
+ path: "/arvados/v1/collections?limit=123",
+ body: `{"offset":456,"include_trash":true,"include_old_versions":true}`,
+ header: http.Header{"X-Http-Method-Override": {"GET"}, "Content-Type": {"application/json"}},
+ shouldCall: "CollectionList",
+ withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
+ },
+ {
+ method: "POST",
+ path: "/arvados/v1/collections?limit=123",
+ body: "offset=456&include_trash=true&include_old_versions=1&_method=GET",
+ header: http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
+ shouldCall: "CollectionList",
+ withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
+ },
+ {
+ method: "PATCH",
+ path: "/arvados/v1/collections",
+ shouldStatus: http.StatusMethodNotAllowed,
+ },
+ {
+ method: "PUT",
+ path: "/arvados/v1/collections",
+ shouldStatus: http.StatusMethodNotAllowed,
+ },
+ {
+ method: "DELETE",
+ path: "/arvados/v1/collections",
+ shouldStatus: http.StatusMethodNotAllowed,
+ },
+ } {
+ // Reset calls captured in previous trial
+ s.stub = arvadostest.APIStub{}
+
+ c.Logf("trial: %#v", trial)
+ _, 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)
+ } else {
+ c.Check(rr.Code, check.Equals, trial.shouldStatus)
+ }
+ calls := s.stub.Calls(nil)
+ if trial.shouldCall == "" {
+ c.Check(calls, check.HasLen, 0)
+ } else if len(calls) != 1 {
+ c.Check(calls, check.HasLen, 1)
+ } else {
+ c.Check(calls[0].Method, isMethodNamed, trial.shouldCall)
+ c.Check(calls[0].Options, check.DeepEquals, trial.withOptions)
+ }
+ }
+}
+
+var _ = check.Suite(&RouterIntegrationSuite{})
+
+type RouterIntegrationSuite struct {
+ rtr *router
+}
+
+func (s *RouterIntegrationSuite) SetUpTest(c *check.C) {
+ cluster := &arvados.Cluster{}
+ cluster.TLS.Insecure = true