Skip to content

Commit

Permalink
test: update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
boltlessengineer committed Aug 22, 2024
1 parent 0d99019 commit b430b8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spec/examples/examples_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("in-place variables", function()
describe("evaluate context across multiple requests", function()
local source = open("spec/examples/variables/in_place_variables.http")
local req_nodes = parser.get_all_request_nodes(source)
assert.same(3, #req_nodes)
assert(#req_nodes >= 3)
local ctx = Context:new()
it("example 1", function()
local req1 = assert(parser.parse(req_nodes[1], source, ctx))
Expand Down
4 changes: 2 additions & 2 deletions spec/examples/variables/in_place_variables.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ GET {{myhost}}/users

###
# so `myhost` here is now `example.net`
# check `spec/examples/script/pre_request_script.http` for variable local to each requests
GET {{myhost}}/stats

###
# check `spec/examples/script/pre_request_script.http` for variable local to each requests
@myhost=bruh
@myhost=this won't affect above request
9 changes: 5 additions & 4 deletions spec/parser/http_parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,25 @@ key5 = value5

describe("variables", function()
it("parse with variables in header", function()
vim.env["TOKEN"] = "xxx"
local source = [[POST https://example.com
X-DATE: {{$date}}
Authorization: Bearer {{TOKEN}}
]]
local _, tree = utils.ts_parse_source(source)
local req_node = assert(tree:root():child(0))
local req = parser.parse(req_node, source)
assert.not_nil(req)
---@cast req rest.Request
assert.same({
["x-date"] = { os.date("%Y-%m-%d") },
["authorization"] = { "Bearer xxx" },
}, req.headers)
end)
it("parse with variables in body", function()
vim.env["DATE"] = "2024-07-28"
local source = [[POST https://example.com
{
"name": "{{DATE}}"
"date": "{{DATE}}"
}
]]
local _, tree = utils.ts_parse_source(source)
Expand All @@ -234,7 +235,7 @@ X-DATE: {{$date}}
assert.same({
__TYPE = "json",
data = [[{
"name": "2024-07-28"
"date": "2024-07-28"
}]],
}, req.body)
end)
Expand Down

0 comments on commit b430b8b

Please sign in to comment.