add test for 2nd part
This commit is contained in:
parent
322c33a69b
commit
28c6126ff8
1 changed files with 19 additions and 3 deletions
22
src/main.zig
22
src/main.zig
|
@ -339,7 +339,12 @@ fn fetchFile(response: *http.Response, request: http.Request, filename: []const
|
|||
|
||||
pub const log_level: std.log.Level = .debug;
|
||||
test "multipart" {
|
||||
const PART1_REAL_BODY = "Hello!\n";
|
||||
const PART1_REAL_BODY =
|
||||
"Hello!\n";
|
||||
|
||||
const PART2_REAL_BODY =
|
||||
"{\"status\": \"OK\"}\n";
|
||||
|
||||
const body =
|
||||
"--1234\r\n" ++
|
||||
"Content-Type: text/plain\r\n" ++
|
||||
|
@ -351,7 +356,7 @@ test "multipart" {
|
|||
// TODO: add 'content-type' support to content-disposition as well
|
||||
"Content-Disposition: form-data; name=file2; filename=data.json\r\n" ++
|
||||
"\r\n" ++
|
||||
"{\"status\": \"OK\"}\n" ++
|
||||
PART2_REAL_BODY ++
|
||||
"--1234--\r\n";
|
||||
|
||||
var buf: [512]u8 = undefined;
|
||||
|
@ -375,5 +380,16 @@ test "multipart" {
|
|||
std.testing.expectEqualSlices(u8, "ab.txt", part1.disposition.filename);
|
||||
std.testing.expectEqualSlices(u8, PART1_REAL_BODY, part1.body);
|
||||
|
||||
// var part2 = (try multipart.next(&hzzp_buffer)).?;
|
||||
var part2 = (try multipart.next(&hzzp_buffer, std.testing.allocator)).?;
|
||||
defer part2.deinit();
|
||||
|
||||
std.debug.warn(
|
||||
"\npart2={}\n",
|
||||
.{part2},
|
||||
);
|
||||
|
||||
std.testing.expectEqualSlices(u8, "application/json", part2.content_type);
|
||||
std.testing.expectEqualSlices(u8, "file2", part2.disposition.name);
|
||||
std.testing.expectEqualSlices(u8, "data.json", part2.disposition.filename);
|
||||
std.testing.expectEqualSlices(u8, PART2_REAL_BODY, part2.body);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue