Skip to content

Commit 21feff9

Browse files
committed
fix tests
1 parent 11ec511 commit 21feff9

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

src/httpfile/assertion_checker.zig

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -294,28 +294,28 @@ fn checkAssertion(
294294
test "Assertion checker with diagnostics - all pass" {
295295
const allocator = std.testing.allocator;
296296

297-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
298-
defer assertions.deinit();
297+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
298+
defer assertions.deinit(allocator);
299299

300-
try assertions.append(HttpParser.Assertion{
300+
try assertions.append(allocator, HttpParser.Assertion{
301301
.key = "status",
302302
.value = "200",
303303
.assertion_type = .equal,
304304
});
305305

306-
try assertions.append(HttpParser.Assertion{
306+
try assertions.append(allocator, HttpParser.Assertion{
307307
.key = "body",
308308
.value = "body content",
309309
.assertion_type = .contains,
310310
});
311311

312-
try assertions.append(HttpParser.Assertion{
312+
try assertions.append(allocator, HttpParser.Assertion{
313313
.key = "body",
314314
.value = "Response body content",
315315
.assertion_type = .equal,
316316
});
317317

318-
try assertions.append(HttpParser.Assertion{
318+
try assertions.append(allocator, HttpParser.Assertion{
319319
.key = "header[\"content-type\"]",
320320
.value = "application/json",
321321
.assertion_type = .equal,
@@ -324,7 +324,7 @@ test "Assertion checker with diagnostics - all pass" {
324324
var request = HttpParser.HttpRequest{
325325
.method = .GET,
326326
.url = "https://api.example.com",
327-
.headers = std.ArrayList(http.Header).init(allocator),
327+
.headers = .empty,
328328
.assertions = assertions,
329329
.body = null,
330330
};
@@ -354,22 +354,22 @@ test "Assertion checker with diagnostics - all pass" {
354354
test "Assertion checker with not_equal - all pass" {
355355
const allocator = std.testing.allocator;
356356

357-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
358-
defer assertions.deinit();
357+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
358+
defer assertions.deinit(allocator);
359359

360-
try assertions.append(HttpParser.Assertion{
360+
try assertions.append(allocator, HttpParser.Assertion{
361361
.key = "status",
362362
.value = "400",
363363
.assertion_type = .not_equal,
364364
});
365365

366-
try assertions.append(HttpParser.Assertion{
366+
try assertions.append(allocator, HttpParser.Assertion{
367367
.key = "body",
368368
.value = "Response body content!!!",
369369
.assertion_type = .not_equal,
370370
});
371371

372-
try assertions.append(HttpParser.Assertion{
372+
try assertions.append(allocator, HttpParser.Assertion{
373373
.key = "header[\"content-type\"]",
374374
.value = "application/xml",
375375
.assertion_type = .not_equal,
@@ -378,7 +378,7 @@ test "Assertion checker with not_equal - all pass" {
378378
var request = HttpParser.HttpRequest{
379379
.method = .GET,
380380
.url = "https://api.example.com",
381-
.headers = std.ArrayList(http.Header).init(allocator),
381+
.headers = .empty,
382382
.assertions = assertions,
383383
.body = null,
384384
};
@@ -408,22 +408,22 @@ test "Assertion checker with not_equal - all pass" {
408408
test "Assertion checker with failures - collects all failures" {
409409
const allocator = std.testing.allocator;
410410

411-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
412-
defer assertions.deinit();
411+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
412+
defer assertions.deinit(allocator);
413413

414-
try assertions.append(HttpParser.Assertion{
414+
try assertions.append(allocator, HttpParser.Assertion{
415415
.key = "status",
416416
.value = "404",
417417
.assertion_type = .equal,
418418
});
419419

420-
try assertions.append(HttpParser.Assertion{
420+
try assertions.append(allocator, HttpParser.Assertion{
421421
.key = "body",
422422
.value = "Wrong body content",
423423
.assertion_type = .equal,
424424
});
425425

426-
try assertions.append(HttpParser.Assertion{
426+
try assertions.append(allocator, HttpParser.Assertion{
427427
.key = "header[\"content-type\"]",
428428
.value = "application/xml",
429429
.assertion_type = .equal,
@@ -432,7 +432,7 @@ test "Assertion checker with failures - collects all failures" {
432432
var request = HttpParser.HttpRequest{
433433
.method = .GET,
434434
.url = "https://api.example.com",
435-
.headers = std.ArrayList(http.Header).init(allocator),
435+
.headers = .empty,
436436
.assertions = assertions,
437437
.body = null,
438438
};
@@ -465,23 +465,23 @@ test "Assertion checker with failures - collects all failures" {
465465

466466
test "HttpParser supports starts_with for status, body, and header" {
467467
const allocator = std.testing.allocator;
468-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
469-
defer assertions.deinit();
468+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
469+
defer assertions.deinit(allocator);
470470

471471
// Status starts with "2"
472-
try assertions.append(HttpParser.Assertion{
472+
try assertions.append(allocator, HttpParser.Assertion{
473473
.key = "status",
474474
.value = "2",
475475
.assertion_type = .starts_with,
476476
});
477477
// Body starts with "Hello"
478-
try assertions.append(HttpParser.Assertion{
478+
try assertions.append(allocator, HttpParser.Assertion{
479479
.key = "body",
480480
.value = "Hello",
481481
.assertion_type = .starts_with,
482482
});
483483
// Header starts with "application"
484-
try assertions.append(HttpParser.Assertion{
484+
try assertions.append(allocator, HttpParser.Assertion{
485485
.key = "header[\"content-type\"]",
486486
.value = "application",
487487
.assertion_type = .starts_with,
@@ -490,7 +490,7 @@ test "HttpParser supports starts_with for status, body, and header" {
490490
var request = HttpParser.HttpRequest{
491491
.method = .GET,
492492
.url = "https://api.example.com",
493-
.headers = std.ArrayList(http.Header).init(allocator),
493+
.headers = .empty,
494494
.assertions = assertions,
495495
.body = null,
496496
};
@@ -519,32 +519,32 @@ test "HttpParser supports starts_with for status, body, and header" {
519519
test "HttpParser supports matches_regex and not_matches_regex for status, body, and headers" {
520520
const allocator = std.testing.allocator;
521521

522-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
523-
defer assertions.deinit();
522+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
523+
defer assertions.deinit(allocator);
524524

525525
// Should pass: status matches regex for 2xx codes
526-
try assertions.append(HttpParser.Assertion{
526+
try assertions.append(allocator, HttpParser.Assertion{
527527
.key = "status",
528528
.value = "^2.*",
529529
.assertion_type = .matches_regex,
530530
});
531531

532532
// Should pass: body matches regex for JSON-like content
533-
try assertions.append(HttpParser.Assertion{
533+
try assertions.append(allocator, HttpParser.Assertion{
534534
.key = "body",
535535
.value = ".*success.*",
536536
.assertion_type = .matches_regex,
537537
});
538538

539539
// Should pass: header matches regex for application/* content types
540-
try assertions.append(HttpParser.Assertion{
540+
try assertions.append(allocator, HttpParser.Assertion{
541541
.key = "header[\"content-type\"]",
542542
.value = "application/.*",
543543
.assertion_type = .matches_regex,
544544
});
545545

546546
// Should pass: status does not match regex for error codes
547-
try assertions.append(HttpParser.Assertion{
547+
try assertions.append(allocator, HttpParser.Assertion{
548548
.key = "status",
549549
.value = "^[45].*",
550550
.assertion_type = .not_matches_regex,
@@ -553,7 +553,7 @@ test "HttpParser supports matches_regex and not_matches_regex for status, body,
553553
var request = HttpParser.HttpRequest{
554554
.method = .GET,
555555
.url = "https://api.example.com",
556-
.headers = std.ArrayList(http.Header).init(allocator),
556+
.headers = .empty,
557557
.assertions = assertions,
558558
.body = null,
559559
};
@@ -582,18 +582,18 @@ test "HttpParser supports matches_regex and not_matches_regex for status, body,
582582
test "HttpParser supports contains and not_contains for headers" {
583583
const allocator = std.testing.allocator;
584584

585-
var assertions = std.ArrayList(HttpParser.Assertion).init(allocator);
586-
defer assertions.deinit();
585+
var assertions: std.ArrayList(HttpParser.Assertion) = .empty;
586+
defer assertions.deinit(allocator);
587587

588588
// Should pass: header contains "json"
589-
try assertions.append(HttpParser.Assertion{
589+
try assertions.append(allocator, HttpParser.Assertion{
590590
.key = "header[\"content-type\"]",
591591
.value = "json",
592592
.assertion_type = .contains,
593593
});
594594

595595
// Should pass: header does not contain "xml"
596-
try assertions.append(HttpParser.Assertion{
596+
try assertions.append(allocator, HttpParser.Assertion{
597597
.key = "header[\"content-type\"]",
598598
.value = "xml",
599599
.assertion_type = .not_contains,
@@ -602,7 +602,7 @@ test "HttpParser supports contains and not_contains for headers" {
602602
var request = HttpParser.HttpRequest{
603603
.method = .GET,
604604
.url = "https://api.example.com",
605-
.headers = std.ArrayList(http.Header).init(allocator),
605+
.headers = .empty,
606606
.assertions = assertions,
607607
.body = null,
608608
};

src/httpfile/http_client.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub const HttpClient = struct {
8484

8585
var header_iterator = raw_response.head.iterateHeaders();
8686
while (header_iterator.next()) |header| {
87-
std.debug.print("{s}, {s}\n", .{ header.name, header.value });
8887
const name = try self.allocator.dupe(u8, header.name);
8988
const value = try self.allocator.dupe(u8, header.value);
9089
try response.headers.put(name, value);
@@ -140,7 +139,7 @@ test "HttpClient basic functionality" {
140139
var client = HttpClient.init(allocator);
141140
defer client.deinit();
142141

143-
var request = httpfiles.HttpRequest.init(allocator);
142+
var request = httpfiles.HttpRequest.init();
144143
defer request.deinit(allocator);
145144

146145
request.method = .GET;

src/httpfile/parser.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ test "HttpParser from String Contents" {
191191
for (requests.items) |*request| {
192192
request.deinit(std.testing.allocator);
193193
}
194-
requests.deinit();
194+
requests.deinit(std.testing.allocator);
195195
}
196196

197197
try std.testing.expectEqual(http.Method.GET, requests.items[0].method);
@@ -220,7 +220,7 @@ test "HttpParser parses assertions" {
220220
for (requests.items) |*request| {
221221
request.deinit(std.testing.allocator);
222222
}
223-
requests.deinit();
223+
requests.deinit(std.testing.allocator);
224224
}
225225

226226
try std.testing.expectEqual(http.Method.GET, requests.items[0].method);

0 commit comments

Comments
 (0)