diff --git a/src/api.zig b/src/api.zig index 161011e..89e51c7 100644 --- a/src/api.zig +++ b/src/api.zig @@ -1692,12 +1692,14 @@ fn serverError(allocator: std.mem.Allocator) HttpResponse { } test "auth allows health without API token" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); var store = try Store.init(std.testing.allocator, ":memory:"); defer store.deinit(); var ctx = Context{ .store = &store, - .allocator = std.testing.allocator, + .allocator = arena.allocator(), .required_api_token = "secret", }; @@ -1706,12 +1708,14 @@ test "auth allows health without API token" { } test "auth rejects protected endpoint without API token" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); var store = try Store.init(std.testing.allocator, ":memory:"); defer store.deinit(); var ctx = Context{ .store = &store, - .allocator = std.testing.allocator, + .allocator = arena.allocator(), .required_api_token = "secret", }; @@ -1720,12 +1724,14 @@ test "auth rejects protected endpoint without API token" { } test "auth accepts admin token for protected endpoint" { + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); var store = try Store.init(std.testing.allocator, ":memory:"); defer store.deinit(); var ctx = Context{ .store = &store, - .allocator = std.testing.allocator, + .allocator = arena.allocator(), .required_api_token = "secret", }; diff --git a/src/config.zig b/src/config.zig index e124be4..0c4d2bb 100644 --- a/src/config.zig +++ b/src/config.zig @@ -81,7 +81,7 @@ test "loadFromFile reads config values" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - try tmp.dir.writeFile(.{ + try std_compat.fs.Dir.wrap(tmp.dir).writeFile(.{ .sub_path = "config.json", .data = \\{ @@ -92,7 +92,7 @@ test "loadFromFile reads config values" { , }); - const cfg_path = try tmp.dir.realpathAlloc(std.testing.allocator, "config.json"); + const cfg_path = try std_compat.fs.Dir.wrap(tmp.dir).realpathAlloc(std.testing.allocator, "config.json"); defer std.testing.allocator.free(cfg_path); var arena = std.heap.ArenaAllocator.init(std.testing.allocator); @@ -108,8 +108,8 @@ test "resolveRelativePaths anchors db to config directory" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - try tmp.dir.makePath("configs"); - try tmp.dir.writeFile(.{ + try std_compat.fs.Dir.wrap(tmp.dir).makePath("configs"); + try std_compat.fs.Dir.wrap(tmp.dir).writeFile(.{ .sub_path = "configs/config.json", .data = \\{ @@ -118,7 +118,7 @@ test "resolveRelativePaths anchors db to config directory" { , }); - const cfg_path = try tmp.dir.realpathAlloc(std.testing.allocator, "configs/config.json"); + const cfg_path = try std_compat.fs.Dir.wrap(tmp.dir).realpathAlloc(std.testing.allocator, "configs/config.json"); defer std.testing.allocator.free(cfg_path); var arena = std.heap.ArenaAllocator.init(std.testing.allocator); diff --git a/src/main.zig b/src/main.zig index 50a84f6..1adcffe 100644 --- a/src/main.zig +++ b/src/main.zig @@ -233,3 +233,11 @@ fn readHttpRequest(allocator: std.mem.Allocator, stream: *std.Io.net.Stream, max return try allocator.dupe(u8, buffer.items[0..required]); } + +// Pull module test declarations into the test build (zig build test). +test { + _ = @import("store.zig"); + _ = @import("api.zig"); + _ = @import("domain.zig"); + _ = @import("config.zig"); +} diff --git a/src/store.zig b/src/store.zig index 14bbe7d..10c4be9 100644 --- a/src/store.zig +++ b/src/store.zig @@ -2422,7 +2422,7 @@ test "claim respects per-state concurrency limits" { // Set per-state concurrency limit of 2 for "review" var concurrency_map: std.json.ObjectMap = .empty; - defer concurrency_map.deinit(); + defer concurrency_map.deinit(alloc); try concurrency_map.put(alloc, "review", .{ .integer = 2 }); const per_state: std.json.Value = .{ .object = concurrency_map };