From fa89eca82dfff8540a229aae7be0962be09d29f4 Mon Sep 17 00:00:00 2001 From: copygirl Date: Fri, 5 Apr 2024 16:54:38 +0200 Subject: [PATCH] Update REST API test --- src/world.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/world.zig b/src/world.zig index b850dd0..363a02e 100644 --- a/src/world.zig +++ b/src/world.zig @@ -303,11 +303,10 @@ pub fn World(comptime ctx: anytype) type { }; } -test "World REST API" { - const expect = @import("./test/expect.zig"); - const alloc = std.testing.allocator; +const expect = @import("./test/expect.zig"); - flecszigble.init(alloc); +test "World REST API" { + flecszigble.init(std.testing.allocator); var world = try World(void).init(); defer world.deinit(); try world.enableRest(42666); @@ -318,16 +317,25 @@ test "World REST API" { } }; + const alloc = std.testing.allocator; var thread = try std.Thread.spawn(.{ .allocator = alloc }, Runner.run, .{world}); defer thread.join(); + // Unsure if compiling or running this takes a really long time, but this + // test using `http.Client` adds about 10s to the test run time. Oh well. const url = "http://localhost:42666/entity/flecs/core/World"; var client = std.http.Client{ .allocator = alloc }; defer client.deinit(); - var result = try client.fetch(alloc, .{ .location = .{ .url = url } }); - defer result.deinit(); - try expect.equalStrings("{\"path\":\"flecs.core.World\", \"ids\":[]}", result.body); + var response = std.ArrayList(u8).init(alloc); + defer response.deinit(); + const result = try client.fetch(.{ + .location = .{ .url = url }, + .response_storage = .{ .dynamic = &response }, + }); + + try expect.equal(std.http.Status.ok, result.status); + try expect.equalStrings("{\"path\":\"flecs.core.World\", \"ids\":[]}", response.items); world.quit(); }