|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|