Reading uri path in tests

Hi!

I’m using 0.14.1
My plugin modifies the path and I want to verify this path in tests.
After some debugging I came to this solution:

local res = assert(proxy_client:send {
method = “PATCH”,
path = “/request/pathBefore”,
body = {},
headers = {}
})
local allRequestInfo = assert.request(res)
assert.equal("/request/pathAfter", allRequestInfo[“kong_request”][“vars”][“uri”])

Is it a hack of accessing table value as [“kong_request”][“vars”][“uri”]?
May this change with a new kong version?
If more “reliable” approach exists?

Thanks!

Probably not the best person to answer but I’ll throw in my 2 cents for what it’s worth.

I’m running 1.0.3 and it seems like the variable is request_uri not uri so yes, be prepared for it to change. That said, I wouldn’t consider it a hack as the same approach is used in tests within the Kong repo. If you want to follow the pattern used in the Kong repo, take a look at https://github.com/Kong/kong/blob/master/spec/03-plugins/22-aws-lambda/01-access_spec.lua. Using the pattern there would mean adjusting your code to something like:

local body = assert.response(res).has.jsonbody()
assert.equal("/request/pathAfter", body.vars.request_uri)

Same same but different I guess. And I have no idea if that code works or not on 0.14 - would depend on how many changes were made to helpers.lua between the versions.

Thanks, verified that it works.
It’s interesting what should I prefer for verification in general - request or response.
Looks like many things duplicate. For example similarly I can check query param in response:

local body = assert.response(res).has.jsonbody()
assert.equals("expected", body.uri_args.myQueryParam)

Or in request:

local allRequestInfo = assert.request(res)
local myRequestParamVal = allRequestInfo.has.queryparam("myQueryParam")
assert.equals("expected", myRequestParamVal)