@@ -3,6 +3,7 @@ package core_test
33import (
44 "context"
55 "encoding/base64"
6+ "github.com/onsi/gomega/gstruct"
67 "io/ioutil"
78 "math/rand"
89 "os"
@@ -247,10 +248,10 @@ var _ = Describe("RequestAccessorV2 tests", func() {
247248 })
248249
249250 It ("Populates stage variables correctly" , func () {
250- varsRequest := getProxyRequest ("orders" , "GET" )
251+ varsRequest := getProxyRequestV2 ("orders" , "GET" )
251252 varsRequest .StageVariables = getStageVariables ()
252253
253- accessor := core.RequestAccessor {}
254+ accessor := core.RequestAccessorV2 {}
254255 httpReq , err := accessor .ProxyEventToHTTPRequest (varsRequest )
255256 Expect (err ).To (BeNil ())
256257
@@ -262,7 +263,7 @@ var _ = Describe("RequestAccessorV2 tests", func() {
262263 Expect ("value1" ).To (Equal (stageVars ["var1" ]))
263264 Expect ("value2" ).To (Equal (stageVars ["var2" ]))
264265
265- stageVars , ok := core .GetStageVarsFromContext (httpReq .Context ())
266+ stageVars , ok := core .GetStageVarsFromContextV2 (httpReq .Context ())
266267 // not present in context
267268 Expect (ok ).To (BeFalse ())
268269
@@ -273,7 +274,7 @@ var _ = Describe("RequestAccessorV2 tests", func() {
273274 // should not be in headers
274275 Expect (err ).ToNot (BeNil ())
275276
276- stageVars , ok = core .GetStageVarsFromContext (httpReq .Context ())
277+ stageVars , ok = core .GetStageVarsFromContextV2 (httpReq .Context ())
277278 Expect (ok ).To (BeTrue ())
278279 Expect (2 ).To (Equal (len (stageVars )))
279280 Expect (stageVars ["var1" ]).ToNot (BeNil ())
@@ -284,9 +285,9 @@ var _ = Describe("RequestAccessorV2 tests", func() {
284285
285286 It ("Populates the default hostname correctly" , func () {
286287
287- basicRequest := getProxyRequest ("orders" , "GET" )
288- basicRequest .RequestContext = getRequestContext ()
289- accessor := core.RequestAccessor {}
288+ basicRequest := getProxyRequestV2 ("orders" , "GET" )
289+ basicRequest .RequestContext = getRequestContextV2 ()
290+ accessor := core.RequestAccessorV2 {}
290291 httpReq , err := accessor .ProxyEventToHTTPRequest (basicRequest )
291292 Expect (err ).To (BeNil ())
292293
@@ -297,8 +298,8 @@ var _ = Describe("RequestAccessorV2 tests", func() {
297298 It ("Uses a custom hostname" , func () {
298299 myCustomHost := "http://my-custom-host.com"
299300 os .Setenv (core .CustomHostVariable , myCustomHost )
300- basicRequest := getProxyRequest ("orders" , "GET" )
301- accessor := core.RequestAccessor {}
301+ basicRequest := getProxyRequestV2 ("orders" , "GET" )
302+ accessor := core.RequestAccessorV2 {}
302303 httpReq , err := accessor .EventToRequestWithContext (context .Background (), basicRequest )
303304 Expect (err ).To (BeNil ())
304305
@@ -310,15 +311,28 @@ var _ = Describe("RequestAccessorV2 tests", func() {
310311 It ("Strips terminating / from hostname" , func () {
311312 myCustomHost := "http://my-custom-host.com"
312313 os .Setenv (core .CustomHostVariable , myCustomHost + "/" )
313- basicRequest := getProxyRequest ("orders" , "GET" )
314- accessor := core.RequestAccessor {}
314+ basicRequest := getProxyRequestV2 ("orders" , "GET" )
315+ accessor := core.RequestAccessorV2 {}
315316 httpReq , err := accessor .EventToRequestWithContext (context .Background (), basicRequest )
316317 Expect (err ).To (BeNil ())
317318
318319 Expect (myCustomHost ).To (Equal ("http://" + httpReq .Host ))
319320 Expect (myCustomHost ).To (Equal ("http://" + httpReq .URL .Host ))
320321 os .Unsetenv (core .CustomHostVariable )
321322 })
323+
324+ It ("handles cookies okay" , func () {
325+ basicRequest := getProxyRequestV2 ("orders" , "GET" )
326+ basicRequest .Cookies = []string {
327+ "TestCookie=123" ,
328+ }
329+ accessor := core.RequestAccessorV2 {}
330+ httpReq , err := accessor .EventToRequestWithContext (context .Background (), basicRequest )
331+ Expect (err ).To (BeNil ())
332+ Expect (httpReq .Cookie ("TestCookie" )).To (gstruct .PointTo (gstruct .MatchFields (gstruct .IgnoreExtras , gstruct.Fields {
333+ "Value" : Equal ("123" ),
334+ })))
335+ })
322336 })
323337})
324338
0 commit comments