Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions src/MicroStack/Services/Ec2/Ec2ServiceHandler.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/MicroStack.Tests/AlbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ await _elb.DeleteLoadBalancerAsync(new DeleteLoadBalancerRequest
});

var descAfter = await _elb.DescribeLoadBalancersAsync(new DescribeLoadBalancersRequest());
descAfter.LoadBalancers.ShouldNotContain(l => l.LoadBalancerArn == lbArn);
(descAfter.LoadBalancers ?? []).ShouldNotContain(l => l.LoadBalancerArn == lbArn);
}

[Fact]
Expand Down Expand Up @@ -211,7 +211,7 @@ await _elb.DeleteTargetGroupAsync(new DeleteTargetGroupRequest
});

var descAfter = await _elb.DescribeTargetGroupsAsync(new DescribeTargetGroupsRequest());
descAfter.TargetGroups.ShouldNotContain(t => t.TargetGroupArn == tgArn);
(descAfter.TargetGroups ?? []).ShouldNotContain(t => t.TargetGroupArn == tgArn);
}

[Fact]
Expand Down Expand Up @@ -404,7 +404,7 @@ await _elb.DeleteListenerAsync(new DeleteListenerRequest
{
LoadBalancerArn = lbArn,
});
descAfter.Listeners.ShouldNotContain(l => l.ListenerArn == lArn);
(descAfter.Listeners ?? []).ShouldNotContain(l => l.ListenerArn == lArn);

await _elb.DeleteTargetGroupAsync(new DeleteTargetGroupRequest { TargetGroupArn = tgArn });
await _elb.DeleteLoadBalancerAsync(new DeleteLoadBalancerRequest { LoadBalancerArn = lbArn });
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public async Task DescribeTargetGroupsByLoadBalancerArn()
{
LoadBalancerArn = lbArn,
});
before.TargetGroups.ShouldNotContain(tg => tg.TargetGroupArn == tgArn);
(before.TargetGroups ?? []).ShouldNotContain(tg => tg.TargetGroupArn == tgArn);

// Create listener to link TG to LB
var lArn = (await _elb.CreateListenerAsync(new CreateListenerRequest
Expand Down
58 changes: 29 additions & 29 deletions tests/MicroStack.Tests/Ec2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task CreateAndDeleteVpc()
await _ec2.DeleteVpcAsync(new DeleteVpcRequest { VpcId = vpcId });

var descAfter = await _ec2.DescribeVpcsAsync(new DescribeVpcsRequest());
descAfter.Vpcs.ShouldNotContain(v => v.VpcId == vpcId);
(descAfter.Vpcs ?? []).ShouldNotContain(v => v.VpcId == vpcId);
}

[Fact]
Expand Down Expand Up @@ -276,7 +276,7 @@ public async Task SecurityGroupCrud()
await _ec2.DeleteSecurityGroupAsync(new DeleteSecurityGroupRequest { GroupId = sgId });

var descAfter = await _ec2.DescribeSecurityGroupsAsync(new DescribeSecurityGroupsRequest());
descAfter.SecurityGroups.ShouldNotContain(sg => sg.GroupId == sgId);
(descAfter.SecurityGroups ?? []).ShouldNotContain(sg => sg.GroupId == sgId);
}

[Fact]
Expand Down Expand Up @@ -347,7 +347,7 @@ await _ec2.RevokeSecurityGroupIngressAsync(new RevokeSecurityGroupIngressRequest
{
GroupIds = [sgId],
});
descAfter.SecurityGroups[0].IpPermissions.ShouldNotContain(p => p.FromPort == 80);
(descAfter.SecurityGroups[0].IpPermissions ?? []).ShouldNotContain(p => p.FromPort == 80);

await _ec2.DeleteSecurityGroupAsync(new DeleteSecurityGroupRequest { GroupId = sgId });
}
Expand All @@ -373,7 +373,7 @@ public async Task KeyPairCrud()
await _ec2.DeleteKeyPairAsync(new DeleteKeyPairRequest { KeyName = "qa-ec2-key" });

var descAfter = await _ec2.DescribeKeyPairsAsync(new DescribeKeyPairsRequest());
descAfter.KeyPairs.ShouldNotContain(kp => kp.KeyName == "qa-ec2-key");
(descAfter.KeyPairs ?? []).ShouldNotContain(kp => kp.KeyName == "qa-ec2-key");
}

[Fact]
Expand Down Expand Up @@ -504,7 +504,7 @@ await _ec2.DisassociateRouteTableAsync(new DisassociateRouteTableRequest
{
RouteTableIds = [rtbId],
});
descAfter.RouteTables[0].Associations.ShouldNotContain(a => a.RouteTableAssociationId == assocId);
(descAfter.RouteTables[0].Associations ?? []).ShouldNotContain(a => a.RouteTableAssociationId == assocId);

await _ec2.DeleteRouteTableAsync(new DeleteRouteTableRequest { RouteTableId = rtbId });
await _ec2.DeleteSubnetAsync(new DeleteSubnetRequest { SubnetId = subnetId });
Expand Down Expand Up @@ -551,7 +551,7 @@ await _ec2.DeleteRouteAsync(new DeleteRouteRequest
{
RouteTableIds = [rtbId],
});
descAfter.RouteTables[0].Routes.ShouldNotContain(r => r.DestinationCidrBlock == "0.0.0.0/0");
(descAfter.RouteTables[0].Routes ?? []).ShouldNotContain(r => r.DestinationCidrBlock == "0.0.0.0/0");

await _ec2.DeleteInternetGatewayAsync(new DeleteInternetGatewayRequest { InternetGatewayId = igwId });
await _ec2.DeleteRouteTableAsync(new DeleteRouteTableRequest { RouteTableId = rtbId });
Expand Down Expand Up @@ -916,7 +916,7 @@ await _ec2.DeleteTagsAsync(new DeleteTagsRequest
InstanceIds = [iid],
});
var tags2 = desc2.Reservations[0].Instances[0].Tags;
tags2.ShouldNotContain(t => t.Key == "Name");
(tags2 ?? []).ShouldNotContain(t => t.Key == "Name");

await _ec2.TerminateInstancesAsync(new TerminateInstancesRequest { InstanceIds = [iid] });
}
Expand Down Expand Up @@ -987,7 +987,7 @@ await _ec2.CreateTagsAsync(new CreateTagsRequest
{
Filters = [new Filter("resource-id", ["i-doesnotexist"])],
});
resp4.Tags.ShouldBeEmpty();
(resp4.Tags ?? []).ShouldBeEmpty();

// All tags have correct resource type
var resp5 = await _ec2.DescribeTagsAsync(new DescribeTagsRequest
Expand Down Expand Up @@ -1032,7 +1032,7 @@ await _ec2.DeleteNetworkInterfaceAsync(new DeleteNetworkInterfaceRequest
});

var descAfter = await _ec2.DescribeNetworkInterfacesAsync(new DescribeNetworkInterfacesRequest());
descAfter.NetworkInterfaces.ShouldNotContain(e => e.NetworkInterfaceId == eniId);
(descAfter.NetworkInterfaces ?? []).ShouldNotContain(e => e.NetworkInterfaceId == eniId);

await _ec2.DeleteSubnetAsync(new DeleteSubnetRequest { SubnetId = subnetId });
await _ec2.DeleteVpcAsync(new DeleteVpcRequest { VpcId = vpcId });
Expand Down Expand Up @@ -1124,7 +1124,7 @@ await _ec2.DeleteVpcEndpointsAsync(new DeleteVpcEndpointsRequest
});

var descAfter = await _ec2.DescribeVpcEndpointsAsync(new DescribeVpcEndpointsRequest());
descAfter.VpcEndpoints.ShouldNotContain(e => e.VpcEndpointId == vpceId);
(descAfter.VpcEndpoints ?? []).ShouldNotContain(e => e.VpcEndpointId == vpceId);

await _ec2.DeleteVpcAsync(new DeleteVpcRequest { VpcId = vpcId });
}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ await _ec2.ModifyVpcEndpointAsync(new ModifyVpcEndpointRequest
{
VpcEndpointIds = [vpceId],
});
desc.VpcEndpoints[0].RouteTableIds.ShouldNotContain(rtbId);
(desc.VpcEndpoints[0].RouteTableIds ?? []).ShouldNotContain(rtbId);

await _ec2.DeleteVpcEndpointsAsync(new DeleteVpcEndpointsRequest { VpcEndpointIds = [vpceId] });
await _ec2.DeleteRouteTableAsync(new DeleteRouteTableRequest { RouteTableId = rtbId });
Expand Down Expand Up @@ -1252,7 +1252,7 @@ await _ec2.AttachVolumeAsync(new AttachVolumeRequest
VolumeIds = [volId],
});
desc2.Volumes[0].State.ShouldBe(VolumeState.Available);
desc2.Volumes[0].Attachments.ShouldBeEmpty();
(desc2.Volumes[0].Attachments ?? []).ShouldBeEmpty();
}

[Fact]
Expand All @@ -1272,7 +1272,7 @@ public async Task DeleteVolume()
{
VolumeIds = [volId],
});
desc.Volumes.ShouldBeEmpty();
(desc.Volumes ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -1416,7 +1416,7 @@ await _ec2.DeleteSnapshotAsync(new DeleteSnapshotRequest
{
SnapshotIds = [snap.Snapshot.SnapshotId],
});
desc.Snapshots.ShouldBeEmpty();
(desc.Snapshots ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -1536,14 +1536,14 @@ public async Task DescribeInstanceCreditSpecifications()
public async Task DescribeSpotInstanceRequests()
{
var resp = await _ec2.DescribeSpotInstanceRequestsAsync(new DescribeSpotInstanceRequestsRequest());
resp.SpotInstanceRequests.ShouldBeEmpty();
(resp.SpotInstanceRequests ?? []).ShouldBeEmpty();
}

[Fact]
public async Task DescribeCapacityReservations()
{
var resp = await _ec2.DescribeCapacityReservationsAsync(new DescribeCapacityReservationsRequest());
resp.CapacityReservations.ShouldBeEmpty();
(resp.CapacityReservations ?? []).ShouldBeEmpty();
}

// ── Describe Prefix Lists ───────────────────────────────────────────────────
Expand Down Expand Up @@ -1818,14 +1818,14 @@ await _ec2.DeleteNetworkAclEntryAsync(new DeleteNetworkAclEntryRequest
{
NetworkAclIds = [aclId],
});
desc3.NetworkAcls[0].Entries.ShouldBeEmpty();
(desc3.NetworkAcls[0].Entries ?? []).ShouldBeEmpty();

await _ec2.DeleteNetworkAclAsync(new DeleteNetworkAclRequest { NetworkAclId = aclId });
var desc4 = await _ec2.DescribeNetworkAclsAsync(new DescribeNetworkAclsRequest
{
NetworkAclIds = [aclId],
});
desc4.NetworkAcls.ShouldBeEmpty();
(desc4.NetworkAcls ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -1881,7 +1881,7 @@ public async Task FlowLogsCrud()
LogDestinationType = LogDestinationType.CloudWatchLogs,
LogGroupName = "/aws/vpc/flowlogs",
});
resp.Unsuccessful.ShouldBeEmpty();
(resp.Unsuccessful ?? []).ShouldBeEmpty();
var flIds = resp.FlowLogIds;
flIds.ShouldHaveSingleItem();
flIds[0].ShouldStartWith("fl-");
Expand All @@ -1899,7 +1899,7 @@ public async Task FlowLogsCrud()
{
FlowLogIds = flIds,
});
desc2.FlowLogs.ShouldBeEmpty();
(desc2.FlowLogs ?? []).ShouldBeEmpty();
}

// ── VPC Peering Tests ───────────────────────────────────────────────────────
Expand Down Expand Up @@ -2003,7 +2003,7 @@ await _ec2.AssociateDhcpOptionsAsync(new AssociateDhcpOptionsRequest
{
DhcpOptionsIds = [doptId],
});
desc2.DhcpOptions.ShouldBeEmpty();
(desc2.DhcpOptions ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -2051,7 +2051,7 @@ await _ec2.DeleteEgressOnlyInternetGatewayAsync(new DeleteEgressOnlyInternetGate
{
EgressOnlyInternetGatewayIds = [eigwId],
});
desc2.EgressOnlyInternetGateways.ShouldBeEmpty();
(desc2.EgressOnlyInternetGateways ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -2113,14 +2113,14 @@ await _ec2.DetachVpnGatewayAsync(new DetachVpnGatewayRequest
{
VpnGatewayIds = [vgwId],
});
desc2.VpnGateways[0].VpcAttachments.ShouldBeEmpty();
(desc2.VpnGateways[0].VpcAttachments ?? []).ShouldBeEmpty();

await _ec2.DeleteVpnGatewayAsync(new DeleteVpnGatewayRequest { VpnGatewayId = vgwId });
var desc3 = await _ec2.DescribeVpnGatewaysAsync(new DescribeVpnGatewaysRequest
{
VpnGatewayIds = [vgwId],
});
desc3.VpnGateways.ShouldBeEmpty();
(desc3.VpnGateways ?? []).ShouldBeEmpty();
}
finally
{
Expand Down Expand Up @@ -2195,7 +2195,7 @@ await _ec2.DeleteCustomerGatewayAsync(new DeleteCustomerGatewayRequest
{
CustomerGatewayIds = [cgwId],
});
desc2.CustomerGateways.ShouldBeEmpty();
(desc2.CustomerGateways ?? []).ShouldBeEmpty();
}

// ── Create Route with NAT Gateway ───────────────────────────────────────────
Expand Down Expand Up @@ -2322,8 +2322,8 @@ await _ec2.ModifyManagedPrefixListAsync(new ModifyManagedPrefixListRequest
PrefixListId = plId,
});
cidrs = entries.Entries.Select(e => e.Cidr).ToList();
cidrs.ShouldNotContain("10.0.0.0/8");
cidrs.ShouldContain("172.16.0.0/12");
(cidrs ?? []).ShouldNotContain("10.0.0.0/8");
(cidrs ?? []).ShouldContain("172.16.0.0/12");

// Delete
await _ec2.DeleteManagedPrefixListAsync(new DeleteManagedPrefixListRequest
Expand All @@ -2334,7 +2334,7 @@ await _ec2.DeleteManagedPrefixListAsync(new DeleteManagedPrefixListRequest
{
PrefixListIds = [plId],
});
desc.PrefixLists.ShouldBeEmpty();
(desc.PrefixLists ?? []).ShouldBeEmpty();
}

// ── Launch Template Tests ───────────────────────────────────────────────────
Expand Down Expand Up @@ -2395,7 +2395,7 @@ await _ec2.DeleteLaunchTemplateAsync(new DeleteLaunchTemplateRequest
{
LaunchTemplateIds = [ltId],
});
desc3.LaunchTemplates.ShouldBeEmpty();
(desc3.LaunchTemplates ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/IamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ await _iam.UntagPolicyAsync(new UntagPolicyRequest

var tags2 = await _iam.ListPolicyTagsAsync(
new ListPolicyTagsRequest { PolicyArn = policyArn });
tags2.Tags.ShouldNotContain(t => t.Key == "env");
(tags2.Tags ?? []).ShouldNotContain(t => t.Key == "env");
}

// ── Update role ─────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -902,6 +902,6 @@ await _iam.DetachUserPolicyAsync(new DetachUserPolicyRequest
EntityFilter = EntityType.Role,
});
(((resp3.PolicyRoles ?? []).Count >= 1)).ShouldBe(true);
resp3.PolicyUsers.ShouldBeEmpty();
(resp3.PolicyUsers ?? []).ShouldBeEmpty();
}
}
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/PersistenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task SnsPersistRoundtrip()
// Reset and verify topic is gone
handler.Reset();
var topics = await _sns.ListTopicsAsync();
topics.Topics.ShouldNotContain(t => t.TopicArn == created.TopicArn);
(topics.Topics ?? []).ShouldNotContain(t => t.TopicArn == created.TopicArn);

// Restore and verify topic is back
handler.RestoreState(state.Value);
Expand Down Expand Up @@ -304,7 +304,7 @@ await Should.ThrowAsync<QueueDoesNotExistException>(
() => _sqs.GetQueueUrlAsync("persist-reset-q"));

var topics = await _sns.ListTopicsAsync();
topics.Topics.ShouldBeEmpty();
(topics.Topics ?? []).ShouldBeEmpty();

await Should.ThrowAsync<ParameterNotFoundException>(
() => _ssm.GetParameterAsync(new GetParameterRequest { Name = "/persist/reset-key" }));
Expand Down
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/RdsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ await _rds.DeleteDBSnapshotAsync(new DeleteDBSnapshotRequest
});

var snaps2 = await _rds.DescribeDBSnapshotsAsync(new DescribeDBSnapshotsRequest());
snaps2.DBSnapshots.ShouldNotContain(s => s.DBSnapshotIdentifier == "qa-rds-snap-1");
(snaps2.DBSnapshots ?? []).ShouldNotContain(s => s.DBSnapshotIdentifier == "qa-rds-snap-1");

await _rds.DeleteDBInstanceAsync(new DeleteDBInstanceRequest
{
Expand Down Expand Up @@ -1030,7 +1030,7 @@ await _rds.RemoveFromGlobalClusterAsync(new RemoveFromGlobalClusterRequest
{
GlobalClusterIdentifier = "test-global-src",
});
resp2.GlobalClusters[0].GlobalClusterMembers.ShouldBeEmpty();
(resp2.GlobalClusters[0].GlobalClusterMembers ?? []).ShouldBeEmpty();

await _rds.DeleteGlobalClusterAsync(new DeleteGlobalClusterRequest
{
Expand Down
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/S3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task DeleteBucket()
await _s3.DeleteBucketAsync("del-bucket-test");

var list = await _s3.ListBucketsAsync();
list.Buckets.ShouldNotContain(b => b.BucketName == "del-bucket-test");
(list.Buckets ?? []).ShouldNotContain(b => b.BucketName == "del-bucket-test");
}

[Fact]
Expand Down Expand Up @@ -285,7 +285,7 @@ public async Task ListObjectsV1()
((resp.CommonPrefixes ?? []).Count).ShouldBe(2);
resp.CommonPrefixes!.ShouldContain("photos/2024/");
resp.CommonPrefixes!.ShouldContain("photos/2025/");
resp.S3Objects.ShouldBeEmpty();
(resp.S3Objects ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/SesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ await _ses.DeleteIdentityAsync(new SesV1.Model.DeleteIdentityRequest
});

var resp = await _ses.ListIdentitiesAsync(new SesV1.Model.ListIdentitiesRequest());
resp.Identities.ShouldNotContain("delete@example.com");
(resp.Identities ?? []).ShouldNotContain("delete@example.com");
}

[Fact]
Expand Down Expand Up @@ -269,7 +269,7 @@ await _ses.DeleteConfigurationSetAsync(new SesV1.Model.DeleteConfigurationSetReq
});

var sets2 = await _ses.ListConfigurationSetsAsync(new SesV1.Model.ListConfigurationSetsRequest());
sets2.ConfigurationSets.ShouldNotContain(s => s.Name == "test-config");
(sets2.ConfigurationSets ?? []).ShouldNotContain(s => s.Name == "test-config");
}

// ═══════════════════════════════════════════════════════════════════════════
Expand Down
4 changes: 2 additions & 2 deletions tests/MicroStack.Tests/SnsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public async Task PublishBatch()
});

(resp.Successful?.Count ?? 0).ShouldBe(3);
resp.Failed.ShouldBeEmpty();
(resp.Failed ?? []).ShouldBeEmpty();
}

[Fact]
Expand Down Expand Up @@ -512,7 +512,7 @@ await _sns.PublishAsync(new PublishRequest
MaxNumberOfMessages = 1,
WaitTimeSeconds = 0,
});
msgs.Messages.ShouldBeEmpty();
(msgs.Messages ?? []).ShouldBeEmpty();

// Publish matching message (blue)
await _sns.PublishAsync(new PublishRequest
Expand Down
Loading