change server test
This commit is contained in:
parent
7c845d097b
commit
84073d812f
2 changed files with 20 additions and 16 deletions
|
@ -174,15 +174,3 @@ test "stringify Response" {
|
|||
defer allocator.free(res_str);
|
||||
try std.testing.expect(eql(u8, res_str, "HTTP/1.1 200 OK\r\nUser-Agent: Testbot\n\r\n\r\nThis is the body!"));
|
||||
}
|
||||
|
||||
test "Run server" {
|
||||
// Set route
|
||||
const rt = [_]types.Route{.{ "/", handlefn }};
|
||||
try Server.listen("0.0.0.0", 8080, &rt, std.testing.allocator);
|
||||
}
|
||||
// Function for test "Run Server"
|
||||
fn handlefn(_: *types.Request) types.Response {
|
||||
// create Response and add cookie to test cookie setting
|
||||
var res = types.Response{ .body = "<h1>Run Server Test OK!</h1>", .cookies = &[_]Response.Cookie{.{ .name = "Test-Cookie", .value = "Test", .domain = "localhost:8080" }} };
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
const status = @import("status.zig");
|
||||
const server = @import("server.zig");
|
||||
|
@ -10,8 +11,23 @@ pub const Response = types.Response;
|
|||
pub const Method = types.Method;
|
||||
pub const HTTP_Version = types.HTTP_Version;
|
||||
|
||||
test "Run all tests" {
|
||||
_ = types;
|
||||
_ = status;
|
||||
_ = server;
|
||||
test "Test zerve test-app, run server and serve test page" {
|
||||
// Set route
|
||||
const rt = [_]types.Route{.{ "/", handlefn }};
|
||||
try Server.listen("0.0.0.0", 8080, &rt, std.testing.allocator);
|
||||
}
|
||||
// Function for test "Run Server"
|
||||
fn handlefn(req: *types.Request) types.Response {
|
||||
// print headers of Request
|
||||
std.debug.print("\nSent headers:\n", .{});
|
||||
for (req.headers) |header| {
|
||||
std.debug.print("{s}: {s}", .{ header.key, header.value });
|
||||
}
|
||||
// print cookies of Request
|
||||
std.debug.print("\nSent cookies:\n", .{});
|
||||
for (req.cookies) |cookie| {
|
||||
std.debug.print("{s}={s}\n", .{ cookie.name, cookie.value });
|
||||
}
|
||||
var res = types.Response{ .body = "<h1>Run Server Test OK!</h1>", .cookies = &[_]Response.Cookie{.{ .name = "Test-Cookie", .value = "Test", .maxAge = 60 * 60 * 5 }} };
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue