Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand All @@ -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",
};

Expand All @@ -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",
};

Expand Down
10 changes: 5 additions & 5 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
\\{
Expand All @@ -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);
Expand All @@ -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 =
\\{
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
2 changes: 1 addition & 1 deletion src/store.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down