a lot of test code, plus a one line ".deinit()" fix
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 7m39s

This commit is contained in:
Emil Lerch 2025-08-25 14:14:15 -07:00
parent 214c580db4
commit cfc8aee1a6
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 46 additions and 14 deletions

View file

@ -262,9 +262,6 @@ pub const AwsHttp = struct {
log.debug("Request url: {s}", .{url}); log.debug("Request url: {s}", .{url});
// TODO: Fix this proxy stuff. This is all a kludge just to compile, but std.http.Client has it all built in now // TODO: Fix this proxy stuff. This is all a kludge just to compile, but std.http.Client has it all built in now
var cl = std.http.Client{ .allocator = self.allocator, .https_proxy = if (self.proxy) |*p| @constCast(p) else null }; var cl = std.http.Client{ .allocator = self.allocator, .https_proxy = if (self.proxy) |*p| @constCast(p) else null };
// Not sure this if statement is correct here. deinit seems to assume
// that client.request was called at least once, but we don't do that
// if we're in a test harness
defer cl.deinit(); // TODO: Connection pooling defer cl.deinit(); // TODO: Connection pooling
const method = std.meta.stringToEnum(std.http.Method, request_cp.method).?; const method = std.meta.stringToEnum(std.http.Method, request_cp.method).?;
@ -289,7 +286,7 @@ pub const AwsHttp = struct {
try m.request(method, uri, req_options) // This will call the test harness try m.request(method, uri, req_options) // This will call the test harness
else else
try cl.request(method, uri, req_options); try cl.request(method, uri, req_options);
defer req.deinit();
// TODO: Need to test for payloads > 2^14. I believe one of our tests does this, but not sure // TODO: Need to test for payloads > 2^14. I believe one of our tests does this, but not sure
// if (request_cp.body.len > 0) { // if (request_cp.body.len > 0) {
// // Workaround for https://github.com/ziglang/zig/issues/15626 // // Workaround for https://github.com/ziglang/zig/issues/15626
@ -318,6 +315,7 @@ pub const AwsHttp = struct {
try req.sendBodyComplete(req_body); try req.sendBodyComplete(req_body);
} else if (options.mock == null) try req.sendBodiless(); } else if (options.mock == null) try req.sendBodiless();
// if (options.mock == null) log.err("Request sent. Body len {d}, uri {f}", .{ request_cp.body.len, uri });
var response = if (options.mock) |m| try m.receiveHead() else try req.receiveHead(&.{}); var response = if (options.mock) |m| try m.receiveHead() else try req.receiveHead(&.{});
// TODO: Timeout - is this now above us? // TODO: Timeout - is this now above us?

View file

@ -5,6 +5,8 @@ const date = @import("date");
const json = @import("json"); const json = @import("json");
const aws = @import("aws.zig"); const aws = @import("aws.zig");
const aws_auth = @import("aws_authentication.zig");
const aws_creds = @import("aws_credentials.zig");
const awshttp = @import("aws_http.zig"); const awshttp = @import("aws_http.zig");
const Services = aws.Services; const Services = aws.Services;
@ -314,8 +316,6 @@ const TestSetup = struct {
}; };
const Self = @This(); const Self = @This();
const aws_creds = @import("aws_credentials.zig");
const aws_auth = @import("aws_authentication.zig");
const signing_time = const signing_time =
date.dateTimeToTimestamp( date.dateTimeToTimestamp(
date.parseIso8601ToDateTime("20230908T170252Z") catch @compileError("Cannot parse date"), date.parseIso8601ToDateTime("20230908T170252Z") catch @compileError("Cannot parse date"),
@ -477,6 +477,7 @@ const TestSetup = struct {
self.allocator.destroy(self.call_options); self.allocator.destroy(self.call_options);
self.call_options = undefined; self.call_options = undefined;
self.allocator.destroy(self); self.allocator.destroy(self);
aws_creds.static_credentials = null;
} }
}; };
test "query_no_input: sts getCallerIdentity comptime" { test "query_no_input: sts getCallerIdentity comptime" {
@ -1367,16 +1368,26 @@ test "works against a live server" {
var conn_reader = connection.stream.reader(&recv_buffer); var conn_reader = connection.stream.reader(&recv_buffer);
var conn_writer = connection.stream.writer(&send_buffer); var conn_writer = connection.stream.writer(&send_buffer);
var http_server = std.http.Server.init(conn_reader.interface(), &conn_writer.interface); var http_server = std.http.Server.init(conn_reader.interface(), &conn_writer.interface);
var req = try http_server.receiveHead(); while (http_server.reader.state == .ready) {
if (req.head.content_length) |l| { var req = try http_server.receiveHead();
if (l == "quit".len) { if (req.head.content_length) |l| {
try req.respond("okie dokie", .{}); if (l == "quit".len) {
return; // We're done here try req.respond("okie dokie", .{ .keep_alive = false });
return; // We're done here
}
if (l == 43) {
// log.err("Got Request", .{});
self.requests_received += 1;
try req.respond(response, .{
.extra_headers = server_response_headers,
.keep_alive = false,
});
continue;
}
return error.UnexpectedRequest;
} }
return error.UnexpectedRequest; return error.MustHaveBodyLength43;
} }
self.requests_received += 1;
try req.respond(response, .{ .extra_headers = server_response_headers });
} }
} }
}; };
@ -1385,8 +1396,31 @@ test "works against a live server" {
try server.start(); try server.start();
var stopped = false; var stopped = false;
defer if (!stopped) server.stop() catch log.err("error stopping server", .{}); defer if (!stopped) server.stop() catch log.err("error stopping server", .{});
// {
// // plain request to see if this is working generally
// var client = std.http.Client{ .allocator = allocator };
// _ = try client.fetch(.{ // we ignore return because that should just shut down
// .method = .GET,
// .location = .{ .url = server.listening_uri },
// });
//
// try server.stop();
// stopped = true;
// try std.testing.expectEqual(@as(usize, 1), server.requests_received);
// if (true) return;
// }
const sts = (Services(.{.sts}){}).sts; const sts = (Services(.{.sts}){}).sts;
const client = aws.Client.init(std.testing.allocator, .{}); const client = aws.Client.init(std.testing.allocator, .{});
const creds = aws_auth.Credentials.init(
allocator,
try allocator.dupe(u8, "ACCESS"),
try allocator.dupe(u8, "SECRET"),
null,
);
aws_creds.static_credentials = creds;
defer aws_creds.static_credentials = null;
const call = try aws.Request(sts.get_caller_identity).call(.{}, .{ .client = client }); const call = try aws.Request(sts.get_caller_identity).call(.{}, .{ .client = client });
// const call = try client.call(services.sts.get_caller_identity.Request{}, options); // const call = try client.call(services.sts.get_caller_identity.Request{}, options);
defer call.deinit(); defer call.deinit();