Skip to content

Commit

Permalink
new: support for passing order to elemental.Request
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed May 1, 2017
1 parent a9204be commit e4310d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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())
})
Expand Down Expand Up @@ -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() {

Expand All @@ -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)
})
})
})
Expand Down

0 comments on commit e4310d8

Please sign in to comment.