| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const http = @import("http"); |
| 3 | 3 | const json = @import("json"); |
| 4 | 4 | const expect = @import("expect").expect; |
| 5 | const extras = @import("extras"); |
| 5 | 6 | const Scheme = enum { http }; |
| 6 | 7 | |
| 7 | 8 | test { |
| ... | ... | @@ -13,18 +14,22 @@ test { |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | 16 | // zig fmt: off |
| 16 | | test { try httpbinMethodGet(.http); } |
| 17 | test { try httpbinMethod(.http, .GET); } |
| 18 | test { try httpbinMethod(.http, .POST); } |
| 19 | test { try httpbinMethod(.http, .PUT); } |
| 20 | test { try httpbinMethod(.http, .PATCH); } |
| 21 | test { try httpbinMethod(.http, .DELETE); } |
| 17 | 22 | // zig fmt: on |
| 18 | 23 | |
| 19 | | fn httpbinMethodGet(comptime scheme: Scheme) !void { |
| 24 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { |
| 20 | 25 | 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); |
| 23 | 28 | defer req.close(allocator); |
| 24 | 29 | try req.writeUA(); |
| 25 | 30 | try req.send(); |
| 26 | 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 | 33 | defer doc.deinit(allocator); |
| 29 | 34 | doc.acquire(); |
| 30 | 35 | defer doc.release(); |