diff --git a/src/aws.zig b/src/aws.zig index 08ac473..78cdd34 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -1815,3 +1815,33 @@ test "ec2_query_no_input: EC2 describe regions" { try std.testing.expectEqualStrings("4cdbdd69-800c-49b5-8474-ae4c17709782", call.response_metadata.request_id); try std.testing.expectEqual(@as(usize, 17), call.response.regions.?.len); } +test "ec2_query_with_input: EC2 describe instances" { + const allocator = std.testing.allocator; + var test_harness = TestSetup.init(allocator, .{ + .allocator = allocator, + .server_response = @embedFile("test_ec2_query_with_input.response"), + .server_response_headers = @constCast(&[_][2][]const u8{ + .{ "Content-Type", "text/xml;charset=UTF-8" }, + .{ "x-amzn-RequestId", "150a14cc-785d-476f-a4c9-2aa4d03b14e2" }, + }), + }); + defer test_harness.deinit(); + const options = try test_harness.start(); + const ec2 = (Services(.{.ec2}){}).ec2; + const call = try test_harness.client.call(ec2.describe_instances.Request{ + .max_results = 6, + }, 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("/?Action=DescribeInstances&Version=2016-11-15", test_harness.request_options.request_target); + try std.testing.expectEqualStrings( + \\Action=DescribeInstances&Version=2016-11-15&MaxResults=6 + , test_harness.request_options.request_body); + // Response expectations + try std.testing.expectEqualStrings("150a14cc-785d-476f-a4c9-2aa4d03b14e2", call.response_metadata.request_id); + try std.testing.expectEqual(@as(usize, 6), call.response.reservations.?.len); + try std.testing.expectEqualStrings("i-0212d7d1f62b96676", call.response.reservations.?[1].instances.?[0].instance_id.?); + try std.testing.expectEqualStrings("123456789012:found-me", call.response.reservations.?[1].instances.?[0].tags.?[0].value.?); +} diff --git a/src/main.zig b/src/main.zig index 4df1244..2906869 100644 --- a/src/main.zig +++ b/src/main.zig @@ -186,7 +186,6 @@ pub fn main() anyerror!void { std.log.info("request id: {any}", .{result.response_metadata.request_id}); std.log.info("region count: {d}", .{result.response.regions.?.len}); }, - // ^^ under test. vv still in progress .ec2_query_with_input => { // Describe instances is more interesting const result = try client.call(services.ec2.describe_instances.Request{ .max_results = 6 }, options); @@ -218,6 +217,7 @@ pub fn main() anyerror!void { next = more.response.next_token; } }, + // ^^ under test. vv still in progress .rest_xml_no_input => { const result = try client.call(services.s3.list_buckets.Request{}, options); defer result.deinit(); diff --git a/src/test_ec2_query_with_input.response b/src/test_ec2_query_with_input.response new file mode 100644 index 0000000..0707542 --- /dev/null +++ b/src/test_ec2_query_with_input.response @@ -0,0 +1,955 @@ + + + 150a14cc-785d-476f-a4c9-2aa4d03b14e2 + + + r-0aa8dc779a7a3a76a + 550620852718 + + + + i-07d9a800b9cf6cb02 + ami-0e9dbfecae1768f17 + + 80 + stopped + + ip-172-31-28-124.us-west-2.compute.internal + + User initiated + 0 + + t3.small + 2023-02-10T22:15:05.000Z + + us-west-2b + + default + + + disabled + + subnet-1f3f4278 + vpc-dc2402bb + 172.31.28.124 + true + + + sg-08f08fa2f77bc26f4 + aws-cloud9-foo-394ec61bf1ca40188ec0701578b99e68-InstanceSecurityGroup-X63389OZJE9A + + + + Client.InstanceInitiatedShutdown + Client.InstanceInitiatedShutdown: Instance initiated shutdown + + x86_64 + ebs + /dev/xvda + + + /dev/xvda + + vol-00f20d00c3e7793db + attached + 2021-07-14T16:56:39.000Z + true + + + + hvm + aws-c-Insta-13W4473LX3CZH + + + aws:cloud9:environment + 394ec61bf1ca40188ec0701578b99e68 + + + aws:cloudformation:logical-id + Instance + + + Name + aws-cloud9-foo-394ec61bf1ca40188ec0701578b99e68 + + + aws:cloud9:owner + 550620852718:admin-nucman + + + aws:cloudformation:stack-name + aws-cloud9-foo-394ec61bf1ca40188ec0701578b99e68 + + + aws:cloudformation:stack-id + arn:aws:cloudformation:us-west-2:550620852718:stack/aws-cloud9-foo-394ec61bf1ca40188ec0701578b99e68/6c4bec10-e4c4-11eb-8338-0266575e789f + + + xen + + + eni-0aea22ab476c131e8 + subnet-1f3f4278 + vpc-dc2402bb + + 550620852718 + in-use + 02:e4:fe:61:88:ad + 172.31.28.124 + ip-172-31-28-124.us-west-2.compute.internal + true + + + sg-08f08fa2f77bc26f4 + aws-cloud9-foo-394ec61bf1ca40188ec0701578b99e68-InstanceSecurityGroup-X63389OZJE9A + + + + eni-attach-031a23d21bd9a9675 + 0 + attached + 2021-07-14T16:56:38.000Z + true + 0 + + + + 172.31.28.124 + ip-172-31-28-124.us-west-2.compute.internal + true + + + + interface + + + false + true + + 1 + 2 + + + open + + + false + + + false + + + applied + optional + 1 + enabled + enabled + disabled + disabled + + + default + + Linux/UNIX + RunInstances + 2021-07-14T16:56:38.000Z + + + + 658754138699 + + + r-0940490b7bdb0836c + 550620852718 + + + + i-0212d7d1f62b96676 + ami-070f8ba3a2c0afce0 + + 80 + stopped + + ip-172-31-30-83.us-west-2.compute.internal + + User initiated + 0 + + t2.micro + 2023-02-11T21:53:47.000Z + + us-west-2b + + default + + + disabled + + subnet-1f3f4278 + vpc-dc2402bb + 172.31.30.83 + true + + + sg-0e3ac4cfe81bc1c2b + aws-cloud9-bar-d504651a56f2445b8982d417aafd085a-InstanceSecurityGroup-1OZKQYO8KIOME + + + + Client.InstanceInitiatedShutdown + Client.InstanceInitiatedShutdown: Instance initiated shutdown + + x86_64 + ebs + /dev/xvda + + + /dev/xvda + + vol-0cc762b2f841ecaf4 + attached + 2021-10-05T19:33:33.000Z + true + + + + hvm + aws-c-Insta-35XWJJQHYLPT + + + aws:cloud9:owner + 123456789012:found-me + + + aws:cloudformation:stack-id + arn:aws:cloudformation:us-west-2:550620852718:stack/aws-cloud9-bar-d504651a56f2445b8982d417aafd085a/17dff4b0-2613-11ec-9c03-06b5f025c307 + + + Name + aws-cloud9-bar-d504651a56f2445b8982d417aafd085a + + + aws:cloudformation:stack-name + aws-cloud9-bar-d504651a56f2445b8982d417aafd085a + + + aws:cloud9:environment + d504651a56f2445b8982d417aafd085a + + + aws:cloudformation:logical-id + Instance + + + xen + + + eni-06d01abe13a5a46bd + subnet-1f3f4278 + vpc-dc2402bb + + 550620852718 + in-use + 02:74:c8:f4:85:15 + 172.31.30.83 + ip-172-31-30-83.us-west-2.compute.internal + true + + + sg-0e3ac4cfe81bc1c2b + aws-cloud9-bar-d504651a56f2445b8982d417aafd085a-InstanceSecurityGroup-1OZKQYO8KIOME + + + + eni-attach-00f488a53bae93f93 + 0 + attached + 2021-10-05T19:33:32.000Z + true + 0 + + + + 172.31.30.83 + ip-172-31-30-83.us-west-2.compute.internal + true + + + + interface + + + + arn:aws:iam::550620852718:instance-profile/cloud9/AWSCloud9SSMInstanceProfile + AIPAYAM4POHXJTV7DRBSG + + false + true + + 1 + 1 + + + open + + + false + + + false + + + applied + optional + 1 + enabled + enabled + disabled + disabled + + + default + + Linux/UNIX + RunInstances + 2021-10-05T19:33:32.000Z + + ip-name + false + false + + + + 658754138699 + + + r-048a68824329ee47a + 550620852718 + + + + i-09bbf88c328330f55 + ami-0d70650c3afa9cf54 + + 16 + running + + ip-172-31-48-236.us-west-2.compute.internal + ec2-44-234-48-55.us-west-2.compute.amazonaws.com + + _gpg + 0 + + c7g.2xlarge + 2022-10-19T15:37:09.000Z + + us-west-2d + + default + + + disabled + + subnet-7ba0e853 + vpc-dc2402bb + 172.31.48.236 + 44.234.48.55 + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + arm64 + ebs + /dev/xvda + + + /dev/xvda + + vol-0a323996268256b3e + attached + 2022-10-19T15:37:10.000Z + true + + + + hvm + + + + Name + arm-me + + + xen + + + eni-0f4c43dfaa43f064b + subnet-7ba0e853 + vpc-dc2402bb + + 550620852718 + in-use + 0e:21:01:2e:ef:c5 + 172.31.48.236 + ip-172-31-48-236.us-west-2.compute.internal + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + + eni-attach-080d7f5a8d0357389 + 0 + attached + 2022-10-19T15:37:09.000Z + true + 0 + + + 44.234.48.55 + ec2-44-234-48-55.us-west-2.compute.amazonaws.com + amazon + + + + 172.31.48.236 + ip-172-31-48-236.us-west-2.compute.internal + true + + 44.234.48.55 + ec2-44-234-48-55.us-west-2.compute.amazonaws.com + amazon + + + + + interface + + + + arn:aws:iam::550620852718:instance-profile/ec2-dev + AIPAYAM4POHXCFNKZ7HU2 + + true + true + + 8 + 1 + + + open + + + false + + + false + + + applied + optional + 1 + enabled + enabled + disabled + disabled + + + default + + uefi + uefi + Linux/UNIX + RunInstances + 2022-10-19T15:37:09.000Z + + ip-name + true + false + + + + + + r-0cfdc8df25b50065c + 550620852718 + + + + i-0e434844bd11cfb89 + ami-0530ca8899fac469f + + 80 + stopped + + ip-172-31-2-86.us-west-2.compute.internal + + User initiated (2023-04-24 18:22:48 GMT) + _gpg + 0 + + m6id.8xlarge + 2023-04-24T18:18:57.000Z + + us-west-2c + + default + + + disabled + + subnet-278b697c + vpc-dc2402bb + 172.31.2.86 + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + + Client.UserInitiatedShutdown + Client.UserInitiatedShutdown: User initiated shutdown + + x86_64 + ebs + /dev/sda1 + + + /dev/sda1 + + vol-0572331907eba7cac + attached + 2022-12-19T22:47:27.000Z + true + + + + hvm + 764d0ed4-c07c-4a2b-ad47-f7898e22679f + + + Name + builder (ubuntu) + + + xen + + + eni-04535f1fa4ad08d3b + subnet-278b697c + vpc-dc2402bb + + 550620852718 + in-use + 0a:b1:ac:e1:ff:7b + 172.31.2.86 + ip-172-31-2-86.us-west-2.compute.internal + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + + eni-attach-00a2004472baad6f5 + 0 + attached + 2022-12-19T22:47:26.000Z + true + 0 + + + + 172.31.2.86 + ip-172-31-2-86.us-west-2.compute.internal + true + + + + interface + + + + arn:aws:iam::550620852718:instance-profile/ec2-dev + AIPAYAM4POHXCFNKZ7HU2 + + true + true + + 16 + 2 + + + open + + + false + + + false + + + applied + optional + 1 + enabled + enabled + disabled + disabled + + + default + + legacy-bios + Linux/UNIX + RunInstances + 2022-12-19T22:47:26.000Z + + ip-name + true + false + + + + + + r-02704dc87c670d484 + 550620852718 + + + + i-0db69c8b15bd5e14c + ami-039965e18092d85cb + + 16 + running + + ip-172-31-6-203.us-west-2.compute.internal + ec2-34-221-53-125.us-west-2.compute.amazonaws.com + + nucman + 0 + + t2.xlarge + 2023-03-04T01:13:26.000Z + + us-west-2c + + default + + windows + + disabled + + subnet-278b697c + vpc-dc2402bb + 172.31.6.203 + 34.221.53.125 + true + + + sg-00ffec335f6c35ce3 + rdp + + + sg-0aab58c6b2bde2105 + outbound + + + x86_64 + ebs + /dev/sda1 + + + /dev/sda1 + + vol-00fbf5327243f6ca5 + attached + 2023-03-04T01:13:27.000Z + true + + + + hvm + 1677892442146 + + + Name + VS/Windows 2022 + + + xen + + + eni-00a01409b0642d384 + subnet-278b697c + vpc-dc2402bb + + 550620852718 + in-use + 0a:0d:5d:1b:3e:e3 + 172.31.6.203 + ip-172-31-6-203.us-west-2.compute.internal + true + + + sg-00ffec335f6c35ce3 + rdp + + + sg-0aab58c6b2bde2105 + outbound + + + + eni-attach-0c7227ad746fb2e90 + 0 + attached + 2023-03-04T01:13:26.000Z + true + 0 + + + 34.221.53.125 + ec2-34-221-53-125.us-west-2.compute.amazonaws.com + amazon + + + + 172.31.6.203 + ip-172-31-6-203.us-west-2.compute.internal + true + + 34.221.53.125 + ec2-34-221-53-125.us-west-2.compute.amazonaws.com + amazon + + + + + interface + + + false + true + + 4 + 1 + + + open + + + false + + + false + + + applied + optional + 1 + enabled + enabled + disabled + disabled + + + default + + legacy-bios + Windows + RunInstances:0002 + 2023-03-04T01:13:26.000Z + + ip-name + true + false + + + + + + r-0b8580eb880225667 + 550620852718 + + + + i-08528bc380ebf5766 + ami-009c5f630e96948cb + + 16 + running + + ip-172-31-4-86.us-west-2.compute.internal + ec2-18-236-210-164.us-west-2.compute.amazonaws.com + + _gpg + 0 + + m6id.4xlarge + 2023-04-24T18:14:17.000Z + + us-west-2c + + default + + + disabled + + subnet-278b697c + vpc-dc2402bb + 172.31.4.86 + 18.236.210.164 + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + x86_64 + ebs + /dev/xvda + + + /dev/xvda + + vol-0fe4f59bf6294fd80 + attached + 2023-04-24T18:14:18.000Z + true + + + + hvm + bf82a221-c1eb-42ac-9df8-e2da9f7863d3 + + + Name + compiler + + + xen + + + eni-0ae047a5c7a7b761e + subnet-278b697c + vpc-dc2402bb + + 550620852718 + in-use + 0a:02:ae:5b:83:a9 + 172.31.4.86 + ip-172-31-4-86.us-west-2.compute.internal + true + + + sg-03741fd6a7596690b + ssh + + + sg-0aab58c6b2bde2105 + outbound + + + + eni-attach-0b6794ae623825c42 + 0 + attached + 2023-04-24T18:14:17.000Z + true + 0 + + + 18.236.210.164 + ec2-18-236-210-164.us-west-2.compute.amazonaws.com + amazon + + + + 172.31.4.86 + ip-172-31-4-86.us-west-2.compute.internal + true + + 18.236.210.164 + ec2-18-236-210-164.us-west-2.compute.amazonaws.com + amazon + + + + + interface + + + true + true + + 8 + 2 + + + open + + + false + + + false + + + applied + required + 2 + enabled + enabled + disabled + disabled + + + default + + uefi-preferred + uefi + Linux/UNIX + RunInstances + 2023-04-24T18:14:17.000Z + + ip-name + true + false + + + + + + eyJ2IjoiMiIsImMiOiJCRjVLT1ROL2FKOWQ1TDA1alpya1hrK2pIdTZqRUdQVlVOUDg2aUduQVdYRzZQRE5nZzhhTS9GNUNJNFVXK29MNFFOVThLS2o5aDNYVjNqbEJ0Z0tSK013Q3kzTGNPZlFCSEVsUUgzblg0SUtmZEtIY096dTZrM1ZCUzNLUTk2TWZEN2kvU1Bjb3pscWR5YVdsY3plYVlSY3JSVlplSTFvdXNnNnZmVzhoemdwTEMwUSs3UkZGa3RESGtFL085cUI0TU4wZjhJaE02STBOdS9BZTQxeEd1b1NGQ08xZ3h1dUVyVDR1aWs9IiwicyI6IjEifQ== +