authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-05 01:19:35 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-05 01:19:35 -08:00
logd646e7d74311bb3ac477d7ede3ccc3d645f7849d
tree33121a16c657ed4a339bded782c114df7ace071f
parent2da5943b532858076886087bebe3a83cf97b5a7a

add httpbinUserAgent test


1 files changed, 15 insertions(+), 0 deletions(-)

test.zig+15
......@@ -19,6 +19,7 @@ test { try httpbinMethod(.http, .POST); }
1919test { try httpbinMethod(.http, .PUT); }
2020test { try httpbinMethod(.http, .PATCH); }
2121test { try httpbinMethod(.http, .DELETE); }
22test { try httpbinUserAgent(.http); }
2223// zig fmt: on
2324
2425fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
......@@ -35,3 +36,17 @@ fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
3536 defer doc.release();
3637 try expect(doc.root.object().getS("url")).toEqualString(url);
3738}
39fn httpbinUserAgent(comptime scheme: Scheme) !void {
40 const allocator = std.testing.allocator;
41 const url = @tagName(scheme) ++ "://httpbin.org/user-agent";
42 var req = try http.open(allocator, .GET, url);
43 defer req.close(allocator);
44 try req.writeUA();
45 try req.send();
46 try expect(req.status).toEqual(.ok);
47 const doc = try json.parse(allocator, "httpbinMethod", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 });
48 defer doc.deinit(allocator);
49 doc.acquire();
50 defer doc.release();
51 try expect(doc.root.object().getS("user-agent")).toEqualString("WIP https://github.com/nektro/zig-net-http");
52}