Add Config structure, TOML parser, and tests for zocket configuration
This commit is contained in:
30
src/config/config.zig
Normal file
30
src/config/config.zig
Normal file
@@ -0,0 +1,30 @@
|
||||
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, "zocket/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);
|
||||
}
|
||||
Reference in New Issue
Block a user