authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-04 18:48:54 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-04 18:49:02 -08:00
log2da5943b532858076886087bebe3a83cf97b5a7a
treea76e8d7b067eb9a86b865b21f0e46cfcec1fd26a
parent7e7a657c703eeadb346d35c7278e4b42d4da0c6d

test the other method endpoints


2 files changed, 11 insertions(+), 5 deletions(-)

test.zig+10-5
......@@ -2,6 +2,7 @@ const std = @import("std");
22const http = @import("http");
33const json = @import("json");
44const expect = @import("expect").expect;
5const extras = @import("extras");
56const Scheme = enum { http };
67
78test {
......@@ -13,18 +14,22 @@ test {
1314}
1415
1516// zig fmt: off
16test { try httpbinMethodGet(.http); }
17test { try httpbinMethod(.http, .GET); }
18test { try httpbinMethod(.http, .POST); }
19test { try httpbinMethod(.http, .PUT); }
20test { try httpbinMethod(.http, .PATCH); }
21test { try httpbinMethod(.http, .DELETE); }
1722// zig fmt: on
1823
19fn httpbinMethodGet(comptime scheme: Scheme) !void {
24fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
2025 const allocator = std.testing.allocator;
21 const url = @tagName(scheme) ++ "://httpbin.org/get";
22 var req = try http.open(allocator, .GET, url);
26 const url = @tagName(scheme) ++ "://httpbin.org/" ++ comptime extras.asciiLowerComptime(@tagName(method));
27 var req = try http.open(allocator, method, url);
2328 defer req.close(allocator);
2429 try req.writeUA();
2530 try req.send();
2631 try expect(req.status).toEqual(.ok);
27 const doc = try json.parse(allocator, "httpbinMethodGet", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 });
32 const doc = try json.parse(allocator, "httpbinMethod", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 });
2833 defer doc.deinit(allocator);
2934 doc.acquire();
3035 defer doc.release();
zigmod.yml+1
......@@ -8,5 +8,6 @@ dependencies:
88 - src: git https://github.com/nektro/zig-whatwg-url
99 - src: git https://github.com/nektro/zig-nio
1010root_dependencies:
11 - src: git https://github.com/nektro/zig-extras
1112 - src: git https://github.com/nektro/zig-json
1213 - src: git https://github.com/nektro/zig-expect