From 61e9bc86adbd8816cda1ab1d2bf1d215eac31091 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 12 Feb 2024 07:43:40 +0100 Subject: [PATCH] embed json file in api test --- src/engine_api/engine_api.zig | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/engine_api/engine_api.zig b/src/engine_api/engine_api.zig index 0abf2dc..338189a 100644 --- a/src/engine_api/engine_api.zig +++ b/src/engine_api/engine_api.zig @@ -86,18 +86,9 @@ test "deserialize sample engine_newPayloadV2" { const json = std.json; const expect = std.testing.expect; - const filePath = "src/engine_api/test_req.json"; + const fileContent = @embedFile("./test_req.json"); - const file = try std.fs.cwd().openFile(filePath, .{}); - defer file.close(); - - const stat = try file.stat(); - - var buffer = try std.testing.allocator.alloc(u8, stat.size); - defer std.testing.allocator.free(buffer); - _ = try file.readAll(buffer); - - const payload = try json.parseFromSlice(EngineAPIRequest, std.testing.allocator, buffer, .{ .ignore_unknown_fields = true }); + const payload = try json.parseFromSlice(EngineAPIRequest, std.testing.allocator, fileContent, .{ .ignore_unknown_fields = true }); defer payload.deinit(); try expect(std.mem.eql(u8, payload.value.method, "engine_newPayloadV2"));