Compare commits

..

No commits in common. "98d27b3145b916fbf24d103c52a294316d1ffdc6" and "17ff6d3e82c1492359b4fd05eb7761dccf6f78c9" have entirely different histories.

2 changed files with 9 additions and 48 deletions

View File

@ -1323,8 +1323,6 @@ const TestOptions = struct {
server_response: []const u8 = "unset", server_response: []const u8 = "unset",
server_response_headers: [][2][]const u8 = &[_][2][]const u8{}, server_response_headers: [][2][]const u8 = &[_][2][]const u8{},
request_body: []u8 = "", request_body: []u8 = "",
request_method: std.http.Method = undefined,
request_target: []const u8 = undefined,
test_server_runtime_uri: ?[]u8 = null, test_server_runtime_uri: ?[]u8 = null,
server_ready: bool = false, server_ready: bool = false,
@ -1338,10 +1336,8 @@ const TestOptions = struct {
} }
fn deinit(self: Self) void { fn deinit(self: Self) void {
if (self.request_body.len > 0) { if (self.request_body.len > 0)
self.allocator.free(self.request_body); self.allocator.free(self.request_body);
self.allocator.free(self.request_target);
}
if (self.test_server_runtime_uri) |_| if (self.test_server_runtime_uri) |_|
self.allocator.free(self.test_server_runtime_uri.?); self.allocator.free(self.test_server_runtime_uri.?);
} }
@ -1400,8 +1396,7 @@ fn processRequest(options: *TestOptions, server: *std.http.Server) !void {
if (res.request.content_length) |l| if (res.request.content_length) |l|
options.request_body = try res.reader().readAllAlloc(options.allocator, @as(usize, l)); options.request_body = try res.reader().readAllAlloc(options.allocator, @as(usize, l));
options.request_method = res.request.method;
options.request_target = try options.allocator.dupe(u8, res.request.target);
log.debug( log.debug(
"tid {d} (server): {d} bytes read from request", "tid {d} (server): {d} bytes read from request",
.{ std.Thread.getCurrentId(), options.request_body.len }, .{ std.Thread.getCurrentId(), options.request_body.len },
@ -1499,7 +1494,7 @@ const TestSetup = struct {
} }
}; };
test "sts getCallerIdentity comptime" { test "sts get_caller_identity comptime" {
const allocator = std.testing.allocator; const allocator = std.testing.allocator;
var test_harness = TestSetup.init(allocator, .{ var test_harness = TestSetup.init(allocator, .{
.allocator = allocator, .allocator = allocator,
@ -1518,13 +1513,9 @@ test "sts getCallerIdentity comptime" {
// 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();
test_harness.stop(); test_harness.stop();
// Request expectations
try std.testing.expectEqual(std.http.Method.POST, test_harness.request_options.request_method);
try std.testing.expectEqualStrings("/", test_harness.request_options.request_target);
try std.testing.expectEqualStrings( try std.testing.expectEqualStrings(
\\Action=GetCallerIdentity&Version=2011-06-15 \\Action=GetCallerIdentity&Version=2011-06-15
, test_harness.request_options.request_body); , test_harness.request_options.request_body);
// Response expectations
try std.testing.expectEqualStrings( try std.testing.expectEqualStrings(
"arn:aws:iam::123456789012:user/admin", "arn:aws:iam::123456789012:user/admin",
call.response.arn.?, call.response.arn.?,
@ -1533,35 +1524,3 @@ test "sts getCallerIdentity comptime" {
try std.testing.expectEqualStrings("123456789012", call.response.account.?); try std.testing.expectEqualStrings("123456789012", call.response.account.?);
try std.testing.expectEqualStrings("8f0d54da-1230-40f7-b4ac-95015c4b84cd", call.response_metadata.request_id); try std.testing.expectEqualStrings("8f0d54da-1230-40f7-b4ac-95015c4b84cd", call.response_metadata.request_id);
} }
test "sqs listQueues runtime" {
const allocator = std.testing.allocator;
var test_harness = TestSetup.init(allocator, .{
.allocator = allocator,
.server_response =
\\{"ListQueuesResponse":{"ListQueuesResult":{"NextExclusiveStartQueueName":null,"NextToken":null,"queueUrls":null},"ResponseMetadata":{"RequestId":"a85e390b-b866-590e-8cae-645f2bbe59c5"}}}
,
.server_response_headers = @constCast(&[_][2][]const u8{
.{ "Content-Type", "application/json" },
.{ "x-amzn-RequestId", "a85e390b-b866-590e-8cae-645f2bbe59c5" },
}),
});
defer test_harness.deinit();
const options = try test_harness.start();
const sqs = (Services(.{.sqs}){}).sqs;
const call = try test_harness.client.call(sqs.list_queues.Request{
.queue_name_prefix = "s",
}, options);
defer call.deinit();
test_harness.stop();
// Request expectations
try std.testing.expectEqual(std.http.Method.POST, test_harness.request_options.request_method);
try std.testing.expectEqualStrings("/", test_harness.request_options.request_target);
try std.testing.expectEqualStrings(
\\Action=ListQueues&Version=2012-11-05&QueueNamePrefix=s
, test_harness.request_options.request_body);
// Response expectations
// TODO: We can get a lot better with this under test
std.log.info("request id: {any}", .{call.response_metadata.request_id});
std.log.info("account has queues with prefix 's': {}", .{call.response.queue_urls != null});
try std.testing.expectEqualStrings("a85e390b-b866-590e-8cae-645f2bbe59c5", call.response_metadata.request_id);
}

View File

@ -1,11 +1,12 @@
const std = @import("std"); const std = @import("std");
const expectEqualStrings = std.testing.expectEqualStrings; const expectEqualStrings = std.testing.expectEqualStrings;
pub fn snakeToCamel(allocator: std.mem.Allocator, name: []const u8) ![]u8 { pub fn snakeToCamel(allocator: std.mem.Allocator, name: []const u8) ![:0]u8 {
var utf8_name = (std.unicode.Utf8View.init(name) catch unreachable).iterator(); var utf8_name = (std.unicode.Utf8View.init(name) catch unreachable).iterator();
var target_inx: usize = 0; var target_inx: usize = 0;
var previous_ascii: u8 = 0; var previous_ascii: u8 = 0;
var rc = try allocator.alloc(u8, name.len); // A single word will take the entire length plus our sentinel
var rc = try allocator.alloc(u8, name.len + 1);
while (utf8_name.nextCodepoint()) |cp| { while (utf8_name.nextCodepoint()) |cp| {
if (cp > 0xff) return error.UnicodeNotSupported; if (cp > 0xff) return error.UnicodeNotSupported;
const ascii_char = @as(u8, @truncate(cp)); const ascii_char = @as(u8, @truncate(cp));
@ -21,8 +22,9 @@ pub fn snakeToCamel(allocator: std.mem.Allocator, name: []const u8) ![]u8 {
previous_ascii = ascii_char; previous_ascii = ascii_char;
} }
// Do we care if the allocator refuses resize? // Do we care if the allocator refuses resize?
_ = allocator.resize(rc, target_inx); _ = allocator.resize(rc, target_inx + 1);
return rc[0..target_inx]; rc[target_inx] = 0; // add zero sentinel
return rc[0..target_inx :0];
} }
pub fn snakeToPascal(allocator: std.mem.Allocator, name: []const u8) ![]u8 { pub fn snakeToPascal(allocator: std.mem.Allocator, name: []const u8) ![]u8 {
const rc = try snakeToCamel(allocator, name); const rc = try snakeToCamel(allocator, name);