From ae07f82dd5c3359d0a423d78331d6c8f76329cd2 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sun, 27 Aug 2023 11:40:56 -0700 Subject: [PATCH] disable ec2_query demos temporarily --- build.zig | 4 +++ src/aws.zig | 19 ++++++++------ src/main.zig | 70 +++++++++++++++++++++++++++------------------------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/build.zig b/build.zig index 633e1c4..02afe4a 100644 --- a/build.zig +++ b/build.zig @@ -42,6 +42,10 @@ pub fn build(b: *Builder) !void { }); exe.addModule("smithy", smithy_dep.module("smithy")); + const module = b.addModule("aws", .{ + .source_file = .{ .path = "src/aws.zig" }, + }); + exe.addModule("aws", module); // TODO: This does not work correctly due to https://github.com/ziglang/zig/issues/16354 // // We are working here with kind of a weird dependency though. So we can do this diff --git a/src/aws.zig b/src/aws.zig index 38feff1..98cafa2 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -1120,6 +1120,10 @@ fn reportTraffic(allocator: std.mem.Allocator, info: []const u8, request: awshtt reporter("{s}\n", .{msg.items}); } +//////////////////////////////////////////////////////////////////////// +// All code below this line is for testing +//////////////////////////////////////////////////////////////////////// + // TODO: Where does this belong really? fn typeForField(comptime T: type, comptime field_name: []const u8) !type { const ti = @typeInfo(T); @@ -1299,10 +1303,6 @@ test "layer object only" { // const r = try json.parse(SResponse, &stream, parser_options); // json.parseFree(SResponse, r, parser_options); -//////////////////////////////////////////////////////////////////////// -// All code below this line is for testing -//////////////////////////////////////////////////////////////////////// - test { // To run nested container tests, either, call `refAllDecls` which will // reference all declarations located in the given argument. @@ -1430,10 +1430,13 @@ fn serve(options: *TestOptions, res: *std.http.Server.Response) ![]const u8 { // try res.headers.append("content-length", try std.fmt.allocPrint(allocator, "{d}", .{server_response.len})); return options.server_response; } -const TestHeader = struct { - name: []const u8, - value: []const u8, -}; + +//////////////////////////////////////////////////////////////////////// +// These will replicate the tests that were in src/main.zig +// The server_response and server_response_headers come from logs of +// a previous run of src/main.zig, with redactions +//////////////////////////////////////////////////////////////////////// + test "sts get_caller_identity comptime" { // std.testing.log_level = .debug; const allocator = std.testing.allocator; diff --git a/src/main.zig b/src/main.zig index a32d884..8aa5553 100644 --- a/src/main.zig +++ b/src/main.zig @@ -180,42 +180,46 @@ pub fn main() anyerror!void { } }, .ec2_query_no_input => { - // Describe regions is a simpler request and easier to debug - const result = try client.call(services.ec2.describe_regions.Request{}, options); - defer result.deinit(); - std.log.info("request id: {any}", .{result.response_metadata.request_id}); - std.log.info("region count: {d}", .{result.response.regions.?.len}); + // TODO: hunt down this compile error: + // fmt.zig:459:5: error: invalid format string 's' for type 'models.ec2.2016-11-15.json.Filter + std.log.err("EC2 functions not yet working in 0.11", .{}); + // // Describe regions is a simpler request and easier to debug + // const result = try client.call(services.ec2.describe_regions.Request{}, options); + // defer result.deinit(); + // std.log.info("request id: {any}", .{result.response_metadata.request_id}); + // std.log.info("region count: {d}", .{result.response.regions.?.len}); }, .ec2_query_with_input => { + std.log.err("EC2 functions not yet working in 0.11", .{}); // Describe instances is more interesting - const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options); - defer result.deinit(); - std.log.info("reservation count: {d}", .{result.response.reservations.?.len}); - var items: usize = 0; - for (result.response.reservations.?) |reservation| { - items += reservation.instances.?.len; - } - std.log.info("items count: {d}", .{items}); - var next = result.response.next_token; - while (next) |next_token| { - std.log.info("more results available: fetching again", .{}); - - const more = try aws.Request(services.ec2.describe_instances) - .call(.{ .next_token = next_token, .max_results = 6 }, options); - defer more.deinit(); - // we could have exactly 6, which means we have a next token(?!) but not - // any actual additional data - if (more.response.reservations == null) break; - std.log.info("reservation count: {d}", .{more.response.reservations.?.len}); - var batch_items: usize = 0; - for (more.response.reservations.?) |reservation| { - batch_items += reservation.instances.?.len; - } - std.log.info("items count: {d}", .{batch_items}); - items += batch_items; - std.log.info("total items count: {d}", .{items}); - next = more.response.next_token; - } + // const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options); + // defer result.deinit(); + // std.log.info("reservation count: {d}", .{result.response.reservations.?.len}); + // var items: usize = 0; + // for (result.response.reservations.?) |reservation| { + // items += reservation.instances.?.len; + // } + // std.log.info("items count: {d}", .{items}); + // var next = result.response.next_token; + // while (next) |next_token| { + // std.log.info("more results available: fetching again", .{}); + // + // const more = try aws.Request(services.ec2.describe_instances) + // .call(.{ .next_token = next_token, .max_results = 6 }, options); + // defer more.deinit(); + // // we could have exactly 6, which means we have a next token(?!) but not + // // any actual additional data + // if (more.response.reservations == null) break; + // std.log.info("reservation count: {d}", .{more.response.reservations.?.len}); + // var batch_items: usize = 0; + // for (more.response.reservations.?) |reservation| { + // batch_items += reservation.instances.?.len; + // } + // std.log.info("items count: {d}", .{batch_items}); + // items += batch_items; + // std.log.info("total items count: {d}", .{items}); + // next = more.response.next_token; + // } }, .rest_xml_no_input => { const result = try client.call(services.s3.list_buckets.Request{}, options);