Compare commits

...

4 Commits

Author SHA1 Message Date
827c90ab8a
add rest json tests (skippped -still leaky
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 5m15s
2023-08-27 23:20:07 -07:00
034172c7b3
progress indicator on main 2023-08-27 23:18:55 -07:00
1b2b51be88
fix path not added on override 2023-08-27 23:18:15 -07:00
c39fc940b9
fix map pattern in zig 0.11 2023-08-27 23:07:35 -07:00
5 changed files with 99 additions and 33 deletions

View File

@ -1713,3 +1713,64 @@ test "json_1_1_query_no_input: ecs listClusters runtime" {
try std.testing.expectEqual(@as(usize, 1), call.response.cluster_arns.?.len);
try std.testing.expectEqualStrings("arn:aws:ecs:us-west-2:550620852718:cluster/web-applicationehjaf-cluster", call.response.cluster_arns.?[0]);
}
test "rest_json_1_query_with_input: lambda listFunctions runtime" {
// TODO: This passes but leaks like a sieve
if (true) return error.SkipZigTest;
const allocator = std.testing.allocator;
var test_harness = TestSetup.init(allocator, .{
.allocator = allocator,
.server_response =
\\{"Functions":[{"Description":"AWS CDK resource provider framework - onEvent (DevelopmentFrontendStack-g650u/com.amazonaws.cdk.custom-resources.amplify-asset-deployment-provider/amplify-asset-deployment-handler-provider)","TracingConfig":{"Mode":"PassThrough"},"VpcConfig":null,"SigningJobArn":null,"SnapStart":{"OptimizationStatus":"Off","ApplyOn":"None"},"RevisionId":"0c62fc74-a692-403d-9206-5fcbad406424","LastModified":"2023-03-01T18:13:15.704+0000","FileSystemConfigs":null,"FunctionName":"DevelopmentFrontendStack--amplifyassetdeploymentha-aZqB9IbZLIKU","Runtime":"nodejs14.x","Version":"$LATEST","PackageType":"Zip","LastUpdateStatus":null,"Layers":null,"FunctionArn":"arn:aws:lambda:us-west-2:550620852718:function:DevelopmentFrontendStack--amplifyassetdeploymentha-aZqB9IbZLIKU","KMSKeyArn":null,"MemorySize":128,"ImageConfigResponse":null,"LastUpdateStatusReason":null,"DeadLetterConfig":null,"Timeout":900,"Handler":"framework.onEvent","CodeSha256":"m4tt+M0l3p8bZvxIDj83dwGrwRW6atCfS/q8AiXCD3o=","Role":"arn:aws:iam::550620852718:role/DevelopmentFrontendStack-amplifyassetdeploymentha-1782JF7WAPXZ3","SigningProfileVersionArn":null,"MasterArn":null,"RuntimeVersionConfig":null,"CodeSize":4307,"State":null,"StateReason":null,"Environment":{"Variables":{"USER_ON_EVENT_FUNCTION_ARN":"arn:aws:lambda:us-west-2:550620852718:function:DevelopmentFrontendStack--amplifyassetdeploymenton-X9iZJSCSPYDH","WAITER_STATE_MACHINE_ARN":"arn:aws:states:us-west-2:550620852718:stateMachine:amplifyassetdeploymenthandlerproviderwaiterstatemachineB3C2FCBE-Ltggp5wBcHWO","USER_IS_COMPLETE_FUNCTION_ARN":"arn:aws:lambda:us-west-2:550620852718:function:DevelopmentFrontendStack--amplifyassetdeploymentis-jaHopLrSSARV"},"Error":null},"EphemeralStorage":{"Size":512},"StateReasonCode":null,"LastUpdateStatusReasonCode":null,"Architectures":["x86_64"]}],"NextMarker":"lslTXFcbLQKkb0vP9Kgh5hUL7C3VghELNGbWgZfxrRCk3eiDRMkct7D8EmptWfHSXssPdS7Bo66iQPTMpVOHZgANewpgGgFGGr4pVjd6VgLUO6qPe2EMAuNDBjUTxm8z6N28yhlUwEmKbrAV/m0k5qVzizwoxFwvyruMbuMx9kADFACSslcabxXl3/jDI4rfFnIsUVdzTLBgPF1hzwrE1f3lcdkBvUp+QgY+Pn3w5QuJmwsp/di8COzFemY89GgOHbLNqsrBsgR/ee2eXoJp0ZkKM4EcBK3HokqBzefLfgR02PnfNOdXwqTlhkSPW0TKiKGIYu3Bw7lSNrLd+q3+wEr7ZakqOQf0BVo3FMRhMHlVYgwUJzwi3ActyH2q6fuqGG1sS0B8Oa/prUpe5fmp3VaA3WpazioeHtrKF78JwCi6/nfQsrj/8ZtXGQOxlwEgvT1CIUaF+CdHY3biezrK0tRZNpkCtHnkPtF9lq2U7+UiKXSW9yzxT8P2b0M/Qh4IVdnw4rncQK/doYriAeOdrs1wjMEJnHWq9lAaEyipoxYcVr/z5+yaC6Gwxdg45p9X1vIAaYMf6IZxyFuua43SYi0Ls+IBk4VvpR2io7T0dCxHAr3WAo3D2dm0y8OsbM59"}
,
.server_response_headers = @constCast(&[_][2][]const u8{
.{ "Content-Type", "application/json" },
.{ "x-amzn-RequestId", "c4025199-226f-4a16-bb1f-48618e9d2ea6" },
}),
});
defer test_harness.deinit();
const options = try test_harness.start();
const lambda = (Services(.{.lambda}){}).lambda;
const call = try test_harness.client.call(lambda.list_functions.Request{
.max_items = 1,
}, options);
defer call.deinit();
test_harness.stop();
// Request expectations
try std.testing.expectEqual(std.http.Method.GET, test_harness.request_options.request_method);
try std.testing.expectEqualStrings("/2015-03-31/functions?MaxItems=1", test_harness.request_options.request_target);
try std.testing.expectEqualStrings(
\\
, test_harness.request_options.request_body);
// Response expectations
try std.testing.expectEqualStrings("c4025199-226f-4a16-bb1f-48618e9d2ea6", call.response_metadata.request_id);
try std.testing.expectEqual(@as(usize, 1), call.response.functions.?.len);
try std.testing.expectEqualStrings("DevelopmentFrontendStack--amplifyassetdeploymentha-aZqB9IbZLIKU", call.response.functions.?[0].function_name.?);
}
test "rest_json_1_query_no_input: lambda listFunctions runtime" {
if (true) return error.SkipZigTest; // TODO: Figure out leaks
const allocator = std.testing.allocator;
var test_harness = TestSetup.init(allocator, .{
.allocator = allocator,
.server_response = @embedFile("test_rest_json_1_query_no_input.response"),
.server_response_headers = @constCast(&[_][2][]const u8{
.{ "Content-Type", "application/json" },
.{ "x-amzn-RequestId", "b2aad11f-36fc-4d0d-ae92-fe0167fb0f40" },
}),
});
defer test_harness.deinit();
const options = try test_harness.start();
const lambda = (Services(.{.lambda}){}).lambda;
const call = try test_harness.client.call(lambda.list_functions.Request{}, options);
defer call.deinit();
test_harness.stop();
// Request expectations
try std.testing.expectEqual(std.http.Method.GET, test_harness.request_options.request_method);
try std.testing.expectEqualStrings("/2015-03-31/functions", test_harness.request_options.request_target);
try std.testing.expectEqualStrings(
\\
, test_harness.request_options.request_body);
// Response expectations
try std.testing.expectEqualStrings("b2aad11f-36fc-4d0d-ae92-fe0167fb0f40", call.response_metadata.request_id);
try std.testing.expectEqual(@as(usize, 1), call.response.functions.?.len);
try std.testing.expectEqualStrings("arn:aws:ecs:us-west-2:550620852718:cluster/web-applicationehjaf-cluster", call.response.functions.?[0].function_name.?);
}

View File

@ -268,7 +268,7 @@ fn endpointForRequest(allocator: std.mem.Allocator, service: []const u8, request
const environment_override = endpoint_override orelse try getEnvironmentVariable(allocator, "AWS_ENDPOINT_URL");
if (environment_override) |override| {
const uri = try allocator.dupe(u8, override);
return endPointFromUri(allocator, uri);
return endPointFromUri(allocator, uri, request.path);
}
// Fallback to us-east-1 if global endpoint does not exist.
const realregion = if (std.mem.eql(u8, options.region, "aws-global")) "us-east-1" else options.region;
@ -359,7 +359,7 @@ fn s3BucketFromPath(path: []const u8) []const u8 {
///
/// allocator: Will be used only to construct the EndPoint struct
/// uri: string constructed in such a way that deallocation is needed
fn endPointFromUri(allocator: std.mem.Allocator, uri: []const u8) !EndPoint {
fn endPointFromUri(allocator: std.mem.Allocator, uri: []const u8, path: []const u8) !EndPoint {
var scheme: []const u8 = "";
var host: []const u8 = "";
var port: u16 = 443;
@ -401,7 +401,7 @@ fn endPointFromUri(allocator: std.mem.Allocator, uri: []const u8) !EndPoint {
.scheme = scheme,
.allocator = allocator,
.port = port,
.path = try allocator.dupe(u8, "/"),
.path = try allocator.dupe(u8, path),
};
}

View File

@ -1817,36 +1817,37 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
}
},
.ObjectBegin => {
// TODO: Fix this, or better yet, try to switch
// back to standard json parse
return error.NotConvertedToZig11;
// We are parsing into a slice, but we have an
// ObjectBegin. This might be ok, iff the type
// follows this pattern: []struct { key: []const u8, value: anytype }
// (could key be anytype?).
// if (!isMapPattern(T))
// return error.UnexpectedToken;
// var arraylist = std.ArrayList(ptrInfo.child).init(allocator);
// errdefer {
// while (arraylist.popOrNull()) |v| {
// parseFree(ptrInfo.child, v, options);
// }
// arraylist.deinit();
// }
// while (true) {
// const key = (try tokens.next()) orelse return error.UnexpectedEndOfJson;
// switch (key) {
// .ObjectEnd => break,
// else => {},
// }
//
// try arraylist.ensureTotalCapacity(arraylist.items.len + 1);
// const key_val = try parseInternal(try typeForField(ptrInfo.child, "key"), key, tokens, options);
// const val = (try tokens.next()) orelse return error.UnexpectedEndOfJson;
// const val_val = try parseInternal(try typeForField(ptrInfo.child, "value"), val, tokens, options);
// arraylist.appendAssumeCapacity(.{ .key = key_val, .value = val_val });
// }
// return arraylist.toOwnedSlice();
if (!isMapPattern(T))
return error.UnexpectedToken;
const key_type = typeForField(ptrInfo.child, "key");
if (key_type == null) return error.UnexpectedToken;
const value_type = typeForField(ptrInfo.child, "value");
if (value_type == null) return error.UnexpectedToken;
var arraylist = std.ArrayList(ptrInfo.child).init(allocator);
errdefer {
while (arraylist.popOrNull()) |v| {
parseFree(ptrInfo.child, v, options);
}
arraylist.deinit();
}
while (true) {
const key = (try tokens.next()) orelse return error.UnexpectedEndOfJson;
switch (key) {
.ObjectEnd => break,
else => {},
}
try arraylist.ensureTotalCapacity(arraylist.items.len + 1);
const key_val = try parseInternal(key_type.?, key, tokens, options);
const val = (try tokens.next()) orelse return error.UnexpectedEndOfJson;
const val_val = try parseInternal(value_type.?, val, tokens, options);
arraylist.appendAssumeCapacity(.{ .key = key_val, .value = val_val });
}
return arraylist.toOwnedSlice();
},
else => return error.UnexpectedToken,
}
@ -1859,7 +1860,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
unreachable;
}
fn typeForField(comptime T: type, comptime field_name: []const u8) !type {
fn typeForField(comptime T: type, comptime field_name: []const u8) ?type {
const ti = @typeInfo(T);
switch (ti) {
.Struct => {
@ -1868,9 +1869,9 @@ fn typeForField(comptime T: type, comptime field_name: []const u8) !type {
return field.type;
}
},
else => return error.TypeIsNotAStruct, // should not hit this
else => return null, //error.TypeIsNotAStruct, // should not hit this
}
return error.FieldNotFound;
return null; //error.FieldNotFound;
}
fn isMapPattern(comptime T: type) bool {
@ -1999,7 +2000,6 @@ test "parse into that allocates a slice" {
}
test "parse into that uses a map pattern" {
if (true) return error.SkipZigTest; // TODO: re-enable when we work through json changes in 0.11 and see if we can move to upstream
const options = ParseOptions{ .allocator = testing.allocator };
const Map = []struct { key: []const u8, value: []const u8 };
const r = try parse(Map, @constCast(&TokenStream.init("{\"foo\": \"bar\"}")), options);

View File

@ -137,6 +137,8 @@ pub fn main() anyerror!void {
std.log.info("request id: {any}", .{call.response_metadata.request_id});
std.log.info("account has clusters: {}", .{call.response.cluster_arns.?.len > 0});
},
// ^^ under test. vv stil in progress
// This has an issue with json.zig
.rest_json_1_query_with_input => {
const call = try client.call(services.lambda.list_functions.Request{
.max_items = 1,
@ -145,6 +147,7 @@ pub fn main() anyerror!void {
std.log.info("request id: {any}", .{call.response_metadata.request_id});
std.log.info("account has functions: {}", .{call.response.functions.?.len > 0});
},
// This is skipped
.rest_json_1_query_no_input => {
const call = try client.call(services.lambda.list_functions.Request{}, options);
defer call.deinit();

File diff suppressed because one or more lines are too long