tcp: initial tests

This commit is contained in:
Aarnav Tale
2024-04-21 02:11:20 -04:00
parent 26935db97b
commit 8185b0f67a
4 changed files with 31 additions and 3 deletions

View File

@ -325,6 +325,7 @@ test {
_ = @import("termio.zig");
_ = @import("input.zig");
_ = @import("cli.zig");
_ = @import("tcp.zig");
_ = @import("surface_mouse.zig");
// Libraries

View File

@ -1,8 +1,8 @@
//! TCP implementation. The TCP implementation is responsible for
//! responding to TCP requests and dispatching them to the app's Mailbox.
pub const Thread = @import("tcp/Thread.zig");
pub const Server = @import("tcp/Server.zig");
test {
@import("std").testing.refAllDecls(@This());
_ = @import("tcp/Command.zig");
_ = @import("tcp/Server.zig");
}

View File

@ -44,4 +44,15 @@ pub const Command = enum {
}
};
// TODO: These need proper testing.
test "Command.parse ping" {
const input = "ping";
const expected = Command.ping;
const result = try Command.parse(input);
try std.testing.expect(result == expected);
}
test "Command.parse invalid input" {
const input = "";
const result = Command.parse(input);
try std.testing.expectError(Command.Error.InvalidInput, result);
}

View File

@ -125,3 +125,19 @@ pub fn parseAddress(raw_addr: ?[:0]const u8) BindError!std.net.Address {
return BindError.InvalidAddress;
}
test "parseAddress unix socket" {
const addr = "unix:///tmp/test.sock";
const expected = try std.net.Address.initUnix("/tmp/test.sock");
const actual = try parseAddress(addr);
const result = std.net.Address.eql(actual, expected);
try std.testing.expect(result == true);
}
test "parseAddress IP address" {
const addr = "tcp://127.0.0.1:9090";
const expected = try std.net.Address.parseIp4("127.0.0.1", 9090);
const actual = try parseAddress(addr);
const result = std.net.Address.eql(actual, expected);
try std.testing.expect(result == true);
}