Migrate away from httpbin for unit tests

This commit is contained in:
Filip Tibell 2023-05-24 11:25:14 +02:00
parent 048b444859
commit 65ea0edc12
No known key found for this signature in database
4 changed files with 15 additions and 12 deletions

View file

@ -1,6 +1,6 @@
local util = require("./util")
local pass, fail = util.pass, util.fail
pass("GET", "https://httpbin.org/status/200", "Request status code - 200")
fail("GET", "https://httpbin.org/status/400", "Request status code - 400")
fail("GET", "https://httpbin.org/status/500", "Request status code - 500")
pass("GET", "https://httpbingo.org/status/200", "Request status code - 200")
fail("GET", "https://httpbingo.org/status/400", "Request status code - 400")
fail("GET", "https://httpbingo.org/status/500", "Request status code - 500")

View file

@ -2,8 +2,8 @@ local util = require("./util")
local pass = util.pass
-- stylua: ignore start
pass("GET", "https://httpbin.org/get", "Request method - GET")
pass("POST", "https://httpbin.org/post", "Request method - POST")
pass("PATCH", "https://httpbin.org/patch", "Request method - PATCH")
pass("PUT", "https://httpbin.org/put", "Request method - PUT")
pass("DELETE", "https://httpbin.org/delete", "Request method - DELETE")
pass("GET", "https://httpbingo.org/get", "Request method - GET")
pass("POST", "https://httpbingo.org/post", "Request method - POST")
pass("PATCH", "https://httpbingo.org/patch", "Request method - PATCH")
pass("PUT", "https://httpbingo.org/put", "Request method - PUT")
pass("DELETE", "https://httpbingo.org/delete", "Request method - DELETE")

View file

@ -10,7 +10,7 @@ local QUERY: { [string]: string } = {
-- as a special non-ascii one that needs url encoding
local response = net.request({
url = "https://httpbin.org/anything",
url = "https://httpbingo.org/anything",
query = QUERY,
})
@ -30,10 +30,13 @@ assert(success, "Failed to decode json response\n" .. tostring(json))
local args = if type(json.args) == "table" then json.args else nil
assert(args ~= nil, "Response body did not contain an args table")
-- The args table should then have the *exact* same contents as our query
-- The args table should then have the same contents as our query,
-- these will however be returned as arrays of strings and not a
-- single string, presumably because http query params support
-- multiple values of the same name, so we just grab the first
for key, value in QUERY do
local received = args[key]
local received = args[key][1]
if received == nil then
error(string.format("Response body did not contain query parameter '%s'", key))
elseif typeof(received) ~= typeof(value) then

View file

@ -1,4 +1,4 @@
local util = require("./util")
local pass = util.pass
pass("GET", "https://httpbin.org/absolute-redirect/3", "Redirect 3 times")
pass("GET", "https://httpbingo.org/absolute-redirect/3", "Redirect 3 times")