Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed json file in api test #23

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
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
Loading