Skip to content

Commit

Permalink
added missing stage property to api event
Browse files Browse the repository at this point in the history
  • Loading branch information
holygrolli committed Nov 2, 2017
1 parent 9bf5c0e commit 9c55b4b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type RequestContext struct {
HTTPMethod string `json:"httpMethod,omitempty"`
RequestID string `json:"requestId,omitempty"`
AccountsID string `json:"accountId,omitempty"`
Stage string `json:"stage,omitempty"`
Identity ContextIdentity `json:"identity,omitempty"`
}

Expand Down Expand Up @@ -88,6 +89,7 @@ func NewEvent(req *http.Request) (*Event, error) {
event.RequestContext.Identity.SourceIP = req.RemoteAddr
event.RequestContext.ResourcePath = req.URL.Path
event.RequestContext.HTTPMethod = req.Method
event.RequestContext.Stage = "prod"

return event, nil

Expand Down
14 changes: 14 additions & 0 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ var _ = Describe("Event", func() {
r.Router().ServeHTTP(rec, req)
})
})

Context("and path parameters on the request", func() {
req, _ := http.NewRequest("GET", "/get/1", new(bytes.Buffer))

It("returns stage property with value \"prod\"", func() {
r.AddFunction(function, func(w http.ResponseWriter, r *http.Request) {
e, _ := NewEvent(r)
Expect(e.RequestContext.Stage).To(BeIdenticalTo("prod"))
})

rec := httptest.NewRecorder()
r.Router().ServeHTTP(rec, req)
})
})

Context("and no path parameters on the request", func() {
req, _ := http.NewRequest("GET", "/get", new(bytes.Buffer))
Expand Down

0 comments on commit 9c55b4b

Please sign in to comment.