31 lines
918 B
Zig
31 lines
918 B
Zig
const Config = @import("models.zig").Config;
|
|
|
|
const std = @import("std");
|
|
const toml = @import("toml");
|
|
|
|
pub fn parse(io: std.Io, allocator: std.mem.Allocator, path: []const u8) !toml.Parsed(Config)
|
|
{
|
|
var parser = toml.Parser(Config).init(allocator);
|
|
defer parser.deinit();
|
|
|
|
return parser.parseFile(io,path);
|
|
}
|
|
|
|
test "parse zocket config"
|
|
{
|
|
var threaded: std.Io.Threaded = .init(std.testing.allocator, .{});
|
|
defer threaded.deinit();
|
|
const io = threaded.io();
|
|
|
|
const allocator = std.testing.allocator;
|
|
|
|
const parsed = try parse(io, allocator, "config/config.toml");
|
|
defer parsed.deinit();
|
|
|
|
const cfg = parsed.value;
|
|
try std.testing.expectEqualStrings("node-01", cfg.node.id);
|
|
try std.testing.expect(cfg.listen.client.enabled);
|
|
try std.testing.expectEqual(@as(usize, 1), cfg.mesh.peers.len);
|
|
try std.testing.expectEqualStrings("node-02", cfg.mesh.peers[0].id);
|
|
}
|