+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
+ 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},
+ },
+ {
+ 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",
+ 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{}