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");...@@ -2,6 +2,7 @@ const std = @import("std");
2const http = @import("http");2const http = @import("http");
3const json = @import("json");3const json = @import("json");
4const expect = @import("expect").expect;4const expect = @import("expect").expect;
5const extras = @import("extras");
5const Scheme = enum { http };6const Scheme = enum { http };
67
7test {8test {
...@@ -13,18 +14,22 @@ test {...@@ -13,18 +14,22 @@ test {
13}14}
1415
15// zig fmt: off16// 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); }
17// zig fmt: on22// zig fmt: on
1823
19fn httpbinMethodGet(comptime scheme: Scheme) !void {24fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void {
20 const allocator = std.testing.allocator;25 const allocator = std.testing.allocator;
21 const url = @tagName(scheme) ++ "://httpbin.org/get";26 const url = @tagName(scheme) ++ "://httpbin.org/" ++ comptime extras.asciiLowerComptime(@tagName(method));
22 var req = try http.open(allocator, .GET, url);27 var req = try http.open(allocator, method, url);
23 defer req.close(allocator);28 defer req.close(allocator);
24 try req.writeUA();29 try req.writeUA();
25 try req.send();30 try req.send();
26 try expect(req.status).toEqual(.ok);31 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 });
28 defer doc.deinit(allocator);33 defer doc.deinit(allocator);
29 doc.acquire();34 doc.acquire();
30 defer doc.release();35 defer doc.release();
zigmod.yml+1
...@@ -8,5 +8,6 @@ dependencies:...@@ -8,5 +8,6 @@ dependencies:
8 - src: git https://github.com/nektro/zig-whatwg-url8 - src: git https://github.com/nektro/zig-whatwg-url
9 - src: git https://github.com/nektro/zig-nio9 - src: git https://github.com/nektro/zig-nio
10root_dependencies:10root_dependencies:
11 - src: git https://github.com/nektro/zig-extras
11 - src: git https://github.com/nektro/zig-json12 - src: git https://github.com/nektro/zig-json
12 - src: git https://github.com/nektro/zig-expect13 - src: git https://github.com/nektro/zig-expect