These are mostly just tests to make sure the wrappers function as written, rather than testing for any specific output. This commit demonstrates the simple value of actually referencing the various wrapper functions, as a variety of really basic compilation errors were caught and addressed.
97 lines
2.3 KiB
Zig
97 lines
2.3 KiB
Zig
const std = @import("std");
|
|
|
|
const nats = @import("nats");
|
|
|
|
test "version" {
|
|
const version = nats.getVersion();
|
|
const vernum = nats.getVersionNumber();
|
|
|
|
try std.testing.expectEqualStrings("3.6.1", version);
|
|
try std.testing.expectEqual(@as(u32, 0x03_06_01), vernum);
|
|
try std.testing.expect(nats.checkCompatibility());
|
|
}
|
|
|
|
test "time" {
|
|
const now = nats.now();
|
|
const nownano = nats.nowInNanoseconds();
|
|
|
|
nats.sleep(1);
|
|
|
|
const later = nats.now();
|
|
const laternano = nats.nowInNanoseconds();
|
|
|
|
try std.testing.expect(later >= now);
|
|
try std.testing.expect(laternano >= nownano);
|
|
}
|
|
|
|
test "init" {
|
|
{
|
|
try nats.init(nats.default_spin_count);
|
|
defer nats.deinit();
|
|
}
|
|
|
|
{
|
|
// a completely random number
|
|
try nats.init(900_142_069);
|
|
nats.deinit();
|
|
}
|
|
|
|
{
|
|
try nats.init(0);
|
|
try nats.deinitWait(1000);
|
|
}
|
|
}
|
|
|
|
test "misc" {
|
|
{
|
|
try nats.init(nats.default_spin_count);
|
|
defer nats.deinit();
|
|
|
|
try nats.setMessageDeliveryPoolSize(500);
|
|
}
|
|
|
|
{
|
|
try nats.init(nats.default_spin_count);
|
|
defer nats.deinit();
|
|
|
|
// just test that the function is wrapped properly
|
|
nats.releaseThreadMemory();
|
|
}
|
|
|
|
blk: {
|
|
try nats.init(nats.default_spin_count);
|
|
defer nats.deinit();
|
|
|
|
// this is a mess of a test that is designed to fail because actually we're
|
|
// testing out the error reporting functions instead of signing. Nice bait
|
|
// and switch.
|
|
const signed = nats.sign("12345678", "12345678") catch {
|
|
const err = nats.getLastError();
|
|
std.debug.print("signing failed: {s}\n", .{err.desc});
|
|
|
|
var stackmem = [_]u8{0} ** 512;
|
|
var stackbuf: []u8 = &stackmem;
|
|
|
|
nats.getLastErrorStack(&stackbuf) catch {
|
|
std.debug.print("Actually, the error stack was too big\n", .{});
|
|
break :blk;
|
|
};
|
|
|
|
std.debug.print("stack: {s}\n", .{stackbuf});
|
|
break :blk;
|
|
};
|
|
|
|
std.heap.raw_c_allocator.free(signed);
|
|
}
|
|
}
|
|
|
|
test "inbox" {
|
|
try nats.init(nats.default_spin_count);
|
|
defer nats.deinit();
|
|
|
|
const inbox = try nats.createInbox();
|
|
defer nats.destroyInbox(inbox);
|
|
|
|
std.debug.print("inbox: {s}\n", .{inbox});
|
|
}
|