srctree

Gregory Mullen parent 4ae6a451 3c23a3f1
add testing.zig

inlinesplit
src/request-data.zig added: 80, removed: 7, total 73
@@ -121,7 +121,6 @@ pub const PostData = struct {
};
 
pub const QueryData = struct {
alloc: Allocator,
rawquery: []const u8,
items: []DataItem,
 
@@ -135,7 +134,6 @@ pub const QueryData = struct {
}
 
return QueryData{
.alloc = a,
.rawquery = query,
.items = items,
};
 
src/request.zig added: 80, removed: 7, total 73
@@ -31,7 +31,7 @@ const zWSGIParam = @import("zwsgi.zig").zWSGIParam;
pub const DownstreamGateway = union(Downstream) {
zwsgi: *zWSGIRequest,
http: *std.http.Server.Request,
buffer: *std.io.FixedBufferStream([]u8),
buffer: std.io.FixedBufferStream([]u8),
 
pub const Error = std.net.Stream.WriteError || std.io.FixedBufferStream([]u8).WriteError;
pub const Writer = std.io.GenericWriter(DownstreamGateway, Error, write);
 
filename was Deleted added: 80, removed: 7, total 73
@@ -0,0 +1,74 @@
pub fn headers() Headers {
return .{
.known = undefined,
.extended = undefined,
};
}
 
const Buffer = std.io.FixedBufferStream([]u8);
const DEFAULT_SIZE = 0x1000000;
 
pub fn request(a: std.mem.Allocator, buf: []u8) Request {
return .{
.accept = "*/*",
.authorization = null,
.cookie_jar = .init(a),
.data = .{
.post = null,
.query = Request.Data.QueryData.init(a, "") catch unreachable,
},
.headers = headers(),
.host = "localhost",
.method = .GET,
.protocol = .default,
.downstream = .{ .buffer = .{ .buffer = buf, .pos = 0 } },
.referer = null,
.remote_addr = "127.0.0.1",
.secure = true,
.uri = "/",
.user_agent = .init("Verse Internal Testing/0.0"),
};
}
 
pub const FrameCtx = struct {
arena: std.heap.ArenaAllocator,
frame: Frame,
buffer: []u8,
 
pub fn init() !FrameCtx {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
const buffer = try arena.allocator().alloc(u8, DEFAULT_SIZE);
const req = request(arena.allocator(), buffer);
return .{
.arena = arena,
.frame = .{
.cookie_jar = .init(arena.allocator()),
// todo lifetime
.alloc = arena.allocator(),
// todo lifetime
.request = &req,
.uri = splitUri("/") catch unreachable,
.auth_provider = undefined,
.response_data = .init(arena.allocator()),
.headers = headers(),
},
.buffer = buffer,
};
}
 
pub fn raze(fc: FrameCtx) void {
fc.arena.deinit();
}
};
 
test {
_ = try FrameCtx.init();
}
 
const std = @import("std");
const Headers = @import("headers.zig");
const Request = @import("request.zig");
const Frame = @import("frame.zig");
const Router = @import("router.zig");
const splitUri = Router.splitUri;
 
src/verse.zig added: 80, removed: 7, total 73
@@ -37,6 +37,7 @@ comptime {
 
test {
std.testing.refAllDecls(@This());
_ = @import("testing.zig");
}
 
const std = @import("std");