srctree

Gregory Mullen parent 3b2f514d 3973a0b2
add publish tests

src/Publish.zig added: 20, removed: 3, total 17
@@ -197,7 +197,7 @@ pub fn send(p: Publish, any: *AnyWriter) !void {
 
const pkt: Packet = .{
.header = .{
.kind = .PUBLISH,
.kind = .publish,
.flags = .{ .qos = if (p.packet_ident != null) .at_least_once else .at_most_once },
},
.body = fbs.getWritten(),
@@ -234,11 +234,28 @@ pub const Ack = struct {
try w.writeByte(@intFromEnum(code));
try w.writeByte(0); //property length;
 
const pkt: Packet = .{ .header = .{ .kind = .PUBACK }, .body = fbs.getWritten() };
const pkt: Packet = .{ .header = .{ .kind = .puback }, .body = fbs.getWritten() };
try pkt.send(any);
}
};
 
test Publish {
const c = Publish{
.topic_name = "publish",
.packet_ident = null,
.properties = &[0]u8{},
.payload = &[0]u8{},
};
var buffer: [0xffff]u8 = undefined;
var fbs = std.io.fixedBufferStream(&buffer);
var writer = fbs.writer();
var any = writer.any();
 
try c.send(&any);
 
try std.testing.expectEqual(fbs.pos, 12);
}
 
const Packet = @import("Packet.zig");
 
const std = @import("std");