add test for single body
This commit is contained in:
parent
4287ae9c2a
commit
c3c019f19f
1 changed files with 40 additions and 1 deletions
41
src/main.zig
41
src/main.zig
|
@ -351,7 +351,7 @@ test "multipart" {
|
|||
"Hello!\n";
|
||||
|
||||
const PART2_REAL_BODY =
|
||||
"{\"status\": \"OK\"}\n";
|
||||
"{\"status\": \"OK\"}";
|
||||
|
||||
const body =
|
||||
"--1234\r\n" ++
|
||||
|
@ -407,3 +407,42 @@ test "multipart" {
|
|||
try multipart.next(&hzzp_buffer, std.testing.allocator),
|
||||
);
|
||||
}
|
||||
|
||||
test "multipart single file" {
|
||||
const PART1_REAL_BODY =
|
||||
"Hello!";
|
||||
|
||||
const body =
|
||||
"--1234\r\n" ++
|
||||
"Content-Type: text/plain\r\n" ++
|
||||
"Content-Disposition: form-data; name=file1; filename=ab.txt\r\n" ++
|
||||
"\r\n" ++
|
||||
PART1_REAL_BODY ++
|
||||
"--1234--\r\n";
|
||||
|
||||
var buf: [512]u8 = undefined;
|
||||
var multipart = try Multipart.init(
|
||||
body,
|
||||
"multipart/form-data; boundary=1234",
|
||||
&buf,
|
||||
);
|
||||
|
||||
var hzzp_buffer: [1024]u8 = undefined;
|
||||
var part1 = (try multipart.next(&hzzp_buffer, std.testing.allocator)).?;
|
||||
defer part1.deinit();
|
||||
|
||||
std.debug.warn(
|
||||
"\npart={}\n",
|
||||
.{part1},
|
||||
);
|
||||
|
||||
std.testing.expectEqualSlices(u8, "text/plain", part1.content_type);
|
||||
std.testing.expectEqualSlices(u8, "file1", part1.disposition.name);
|
||||
std.testing.expectEqualSlices(u8, "ab.txt", part1.disposition.filename);
|
||||
std.testing.expectEqualSlices(u8, PART1_REAL_BODY, part1.body);
|
||||
|
||||
std.testing.expectEqual(
|
||||
@as(?Part, null),
|
||||
try multipart.next(&hzzp_buffer, std.testing.allocator),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue