diff --git a/test.zig b/test.zig index b64d2d09c83b596bb4355f69717d2be23f0ce226..d2987c845254c2522c2fb2ba403d209e1ce12cb9 100644 --- a/test.zig +++ b/test.zig @@ -2,6 +2,7 @@ const std = @import("std"); const http = @import("http"); const json = @import("json"); const expect = @import("expect").expect; +const extras = @import("extras"); const Scheme = enum { http }; test { @@ -13,18 +14,22 @@ test { } // zig fmt: off -test { try httpbinMethodGet(.http); } +test { try httpbinMethod(.http, .GET); } +test { try httpbinMethod(.http, .POST); } +test { try httpbinMethod(.http, .PUT); } +test { try httpbinMethod(.http, .PATCH); } +test { try httpbinMethod(.http, .DELETE); } // zig fmt: on -fn httpbinMethodGet(comptime scheme: Scheme) !void { +fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { const allocator = std.testing.allocator; - const url = @tagName(scheme) ++ "://httpbin.org/get"; - var req = try http.open(allocator, .GET, url); + const url = @tagName(scheme) ++ "://httpbin.org/" ++ comptime extras.asciiLowerComptime(@tagName(method)); + var req = try http.open(allocator, method, url); defer req.close(allocator); try req.writeUA(); try req.send(); try expect(req.status).toEqual(.ok); - const doc = try json.parse(allocator, "httpbinMethodGet", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 }); + const doc = try json.parse(allocator, "httpbinMethod", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 }); defer doc.deinit(allocator); doc.acquire(); defer doc.release(); diff --git a/zigmod.yml b/zigmod.yml index 63ca8b5170d54c6fa54a0dfc24f9ab06fc6a9a1c..ed8188cbea1b9accb578150593cc25151000c158 100644 --- a/zigmod.yml +++ b/zigmod.yml @@ -8,5 +8,6 @@ dependencies: - src: git https://github.com/nektro/zig-whatwg-url - src: git https://github.com/nektro/zig-nio root_dependencies: + - src: git https://github.com/nektro/zig-extras - src: git https://github.com/nektro/zig-json - src: git https://github.com/nektro/zig-expect