-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.zig
79 lines (59 loc) · 1.89 KB
/
test.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const std = @import("std");
const http = std.http;
const StdClient = @import("Client.zig");
const hasync = @import("http.zig");
pub const IO = @import("tigerbeetle-io/io.zig").IO;
test "blocking mode fetch API" {
const alloc = std.testing.allocator;
var io = try IO.init(32, 0);
defer io.deinit();
var client: StdClient = .{
.allocator = alloc,
.io = &io,
};
defer client.deinit();
// force client's CA cert scan from system.
try client.ca_bundle.rescan(client.allocator);
var res = try client.fetch(alloc, .{
.location = .{ .uri = try std.Uri.parse("https://blg.tch.re") },
.payload = .none,
});
defer res.deinit();
try std.testing.expect(res.status == .ok);
}
test "blocking mode open/send/wait API" {
const alloc = std.testing.allocator;
var io = try IO.init(32, 0);
defer io.deinit();
var client: StdClient = .{
.allocator = alloc,
.io = &io,
};
defer client.deinit();
// force client's CA cert scan from system.
try client.ca_bundle.rescan(client.allocator);
var headers = try std.http.Headers.initList(alloc, &[_]std.http.Field{});
defer headers.deinit();
var req = try client.open(.GET, try std.Uri.parse("https://blg.tch.re"), headers, .{});
defer req.deinit();
try req.send(.{});
try req.finish();
try req.wait();
try std.testing.expect(req.response.status == .ok);
}
test "non blocking mode API" {
const alloc = std.testing.allocator;
var io = try IO.init(32, 0);
defer io.deinit();
var client = hasync.Client.init(alloc, &io);
defer client.deinit();
var reqs: [10]hasync.Request = undefined;
for (0..reqs.len) |i| {
reqs[i] = client.create(try std.Uri.parse("https://up.tch.re"));
try reqs[i].fetch();
}
for (0..reqs.len) |i| {
try reqs[i].wait();
reqs[i].deinit();
}
}