"bytes"
"encoding/json"
"io"
+ "mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
- "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+ "git.arvados.org/arvados.git/sdk/go/arvados"
+ "git.arvados.org/arvados.git/sdk/go/arvadostest"
check "gopkg.in/check.v1"
)
}
if tr.json {
req.Header.Set("Content-Type", "application/json")
- } else {
+ } else if tr.header.Get("Content-Type") == "" {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
for k, v := range tr.header {
func (s *RouterSuite) TestAttrsInBody(c *check.C) {
attrs := map[string]interface{}{"foo": "bar"}
+
+ multipartBody := new(bytes.Buffer)
+ multipartWriter := multipart.NewWriter(multipartBody)
+ multipartWriter.WriteField("attrs", `{"foo":"bar"}`)
+ multipartWriter.Close()
+
for _, tr := range []testReq{
{attrsKey: "model_name", json: true, attrs: attrs},
{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: true},
{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: true, jsonStringParam: true},
{attrsKey: "model_name", json: true, attrs: attrs, jsonAttrsTop: false, jsonStringParam: true},
+ {body: multipartBody, header: http.Header{"Content-Type": []string{multipartWriter.FormDataContentType()}}},
} {
c.Logf("tr: %#v", tr)
req := tr.Request()
- params, err := s.rtr.loadRequestParams(req, tr.attrsKey)
+ var opts struct{ Attrs struct{ Foo string } }
+ params, err := s.rtr.loadRequestParams(req, tr.attrsKey, &opts)
c.Logf("params: %#v", params)
c.Assert(err, check.IsNil)
c.Check(params, check.NotNil)
- c.Assert(params["attrs"], check.FitsTypeOf, map[string]interface{}{})
- c.Check(params["attrs"].(map[string]interface{})["foo"], check.Equals, "bar")
+ c.Check(opts.Attrs.Foo, check.Equals, "bar")
+ if c.Check(params["attrs"], check.FitsTypeOf, map[string]interface{}{}) {
+ c.Check(params["attrs"].(map[string]interface{})["foo"], check.Equals, "bar")
+ }
}
}
c.Logf("#%d, tr: %#v", i, tr)
req := tr.Request()
c.Logf("tr.body: %s", tr.bodyContent())
- params, err := s.rtr.loadRequestParams(req, tr.attrsKey)
+ var opts struct{ EnsureUniqueName bool }
+ params, err := s.rtr.loadRequestParams(req, tr.attrsKey, &opts)
c.Logf("params: %#v", params)
c.Assert(err, check.IsNil)
- c.Check(params, check.NotNil)
- c.Check(params[testKey], check.Equals, false)
+ c.Check(opts.EnsureUniqueName, check.Equals, false)
+ if c.Check(params, check.NotNil) {
+ c.Check(params[testKey], check.Equals, false)
+ }
}
for i, tr := range []testReq{
c.Logf("#%d, tr: %#v", i, tr)
req := tr.Request()
c.Logf("tr.body: %s", tr.bodyContent())
- params, err := s.rtr.loadRequestParams(req, tr.attrsKey)
+ var opts struct {
+ EnsureUniqueName bool `json:"ensure_unique_name"`
+ }
+ params, err := s.rtr.loadRequestParams(req, tr.attrsKey, &opts)
c.Logf("params: %#v", params)
c.Assert(err, check.IsNil)
- c.Check(params, check.NotNil)
- c.Check(params[testKey], check.Equals, true)
+ c.Check(opts.EnsureUniqueName, check.Equals, true)
+ if c.Check(params, check.NotNil) {
+ c.Check(params[testKey], check.Equals, true)
+ }
}
}
} {
c.Logf("#%d, tr: %#v", i, tr)
req := tr.Request()
- params, err := s.rtr.loadRequestParams(req, tr.attrsKey)
+ params, err := s.rtr.loadRequestParams(req, tr.attrsKey, nil)
c.Assert(err, check.IsNil)
c.Assert(params, check.NotNil)
if order, ok := params["order"]; ok && order != nil {
} {
c.Logf("#%d, tr: %#v", i, tr)
req := tr.Request()
- params, err := s.rtr.loadRequestParams(req, tr.attrsKey)
+ var opts arvados.ListOptions
+ params, err := s.rtr.loadRequestParams(req, tr.attrsKey, &opts)
c.Assert(err, check.IsNil)
+ c.Check(opts.Order, check.DeepEquals, []string{"foo", "bar desc"})
if _, ok := params["order"].([]string); ok {
c.Check(params["order"], check.DeepEquals, []string{"foo", "bar desc"})
} else {