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); }...@@ -19,6 +19,7 @@ test { try httpbinMethod(.http, .POST); }
19test { try httpbinMethod(.http, .PUT); }19test { try httpbinMethod(.http, .PUT); }
20test { try httpbinMethod(.http, .PATCH); }20test { try httpbinMethod(.http, .PATCH); }
21test { try httpbinMethod(.http, .DELETE); }21test { try httpbinMethod(.http, .DELETE); }
22test { try httpbinUserAgent(.http); }
22// zig fmt: on23// zig fmt: on
2324
24fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {25fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
...@@ -35,3 +36,17 @@ fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {...@@ -35,3 +36,17 @@ fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
35 defer doc.release();36 defer doc.release();
36 try expect(doc.root.object().getS("url")).toEqualString(url);37 try expect(doc.root.object().getS("url")).toEqualString(url);
37}38}
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}