Skip to content

Commit

Permalink
embed json file in api test
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Feb 12, 2024
1 parent 874497a commit 61e9bc8
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/engine_api/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 61e9bc8

Please sign in to comment.