diff --git a/request.go b/request.go index f009acb..c4af9d1 100644 --- a/request.go +++ b/request.go @@ -23,6 +23,7 @@ type Request struct { Recursive bool `json:"recursive"` Operation Operation `json:"operation"` Identity Identity `json:"identity"` + Order []string `json:"order"` ObjectID string `json:"objectID"` ParentIdentity Identity `json:"parentIdentity"` ParentID string `json:"parentID"` @@ -206,6 +207,7 @@ func NewRequestFromHTTPRequest(req *http.Request) (*Request, error) { ExternalTrackingID: req.Header.Get("X-External-Tracking-ID"), ExternalTrackingType: req.Header.Get("X-External-Tracking-Type"), wireContext: wireContext, + Order: req.URL.Query()["order"], }, nil } @@ -291,6 +293,7 @@ func (r *Request) Duplicate() *Request { req.wireContext = r.wireContext req.ExternalTrackingID = r.ExternalTrackingID req.ExternalTrackingType = r.ExternalTrackingType + req.Order = append([]string{}, r.Order...) for k, v := range r.Headers { req.Headers[k] = v diff --git a/request_test.go b/request_test.go index d62af60..7675d0e 100644 --- a/request_test.go +++ b/request_test.go @@ -285,13 +285,17 @@ func TestRequest_FromHttp(t *testing.T) { Convey("Then the Data should be correct", func() { So(string(r.Data), ShouldEqual, `{"name": "toto"}`) }) + + Convey("Then the order should be nil", func() { + So(r.Order, ShouldBeNil) + }) }) }) Convey("Given I have a post http request on /lists", t, func() { buffer := bytes.NewBuffer([]byte(`{"name": "toto"}`)) - req, _ := http.NewRequest(http.MethodPost, "http://server/lists?p=v", buffer) + req, _ := http.NewRequest(http.MethodPost, "http://server/lists?p=v&order=name&order=toto", buffer) req.Header.Add("X-Namespace", "ns") req.Header.Add("Authorization", "user pass") @@ -319,6 +323,10 @@ func TestRequest_FromHttp(t *testing.T) { So(r.RequestID, ShouldNotBeEmpty) }) + Convey("Then the order should be correct", func() { + So(r.Order, ShouldResemble, []string{"name", "toto"}) + }) + Convey("Then the parameters should be correct", func() { So(r.Parameters, ShouldResemble, req.URL.Query()) }) @@ -722,6 +730,7 @@ func TestRequest_Duplicate(t *testing.T) { req.Recursive = true req.Username = "user" req.Version = 12 + req.Order = []string{"key1", "key2"} Convey("When I use Duplicate()", func() { @@ -745,6 +754,7 @@ func TestRequest_Duplicate(t *testing.T) { So(req2.RequestID, ShouldNotEqual, req.RequestID) So(req2.RequestID, ShouldNotEqual, req.RequestID) So(req2.Version, ShouldEqual, req.Version) + So(req2.Order, ShouldResemble, req.Order) }) }) })