@@ -48,18 +48,19 @@ type CapacityPool struct {
4848type EC2Behavior struct {
4949 DescribeImagesOutput AtomicPtr [ec2.DescribeImagesOutput ]
5050 DescribeLaunchTemplatesOutput AtomicPtr [ec2.DescribeLaunchTemplatesOutput ]
51- DescribeSubnetsOutput AtomicPtr [ec2.DescribeSubnetsOutput ]
52- DescribeSecurityGroupsOutput AtomicPtr [ec2.DescribeSecurityGroupsOutput ]
5351 DescribeInstanceTypesOutput AtomicPtr [ec2.DescribeInstanceTypesOutput ]
5452 DescribeInstanceTypeOfferingsOutput AtomicPtr [ec2.DescribeInstanceTypeOfferingsOutput ]
5553 DescribeAvailabilityZonesOutput AtomicPtr [ec2.DescribeAvailabilityZonesOutput ]
5654 DescribeSpotPriceHistoryBehavior MockedFunction [ec2.DescribeSpotPriceHistoryInput , ec2.DescribeSpotPriceHistoryOutput ]
5755 CreateFleetBehavior MockedFunction [ec2.CreateFleetInput , ec2.CreateFleetOutput ]
5856 TerminateInstancesBehavior MockedFunction [ec2.TerminateInstancesInput , ec2.TerminateInstancesOutput ]
5957 DescribeInstancesBehavior MockedFunction [ec2.DescribeInstancesInput , ec2.DescribeInstancesOutput ]
58+ DescribeSubnetsBehavior MockedFunction [ec2.DescribeSubnetsInput , ec2.DescribeSubnetsOutput ]
59+ DescribeSecurityGroupsBehavior MockedFunction [ec2.DescribeSecurityGroupsInput , ec2.DescribeSecurityGroupsOutput ]
6060 CreateTagsBehavior MockedFunction [ec2.CreateTagsInput , ec2.CreateTagsOutput ]
6161 CalledWithCreateLaunchTemplateInput AtomicPtrSlice [ec2.CreateLaunchTemplateInput ]
6262 CalledWithDescribeImagesInput AtomicPtrSlice [ec2.DescribeImagesInput ]
63+ Subnets sync.Map
6364 Instances sync.Map
6465 LaunchTemplates sync.Map
6566 InsufficientCapacityPools atomic.Slice [CapacityPool ]
@@ -83,8 +84,8 @@ var DefaultSupportedUsageClasses = []ec2types.UsageClassType{ec2types.UsageClass
8384func (e * EC2API ) Reset () {
8485 e .DescribeImagesOutput .Reset ()
8586 e .DescribeLaunchTemplatesOutput .Reset ()
86- e .DescribeSubnetsOutput .Reset ()
87- e .DescribeSecurityGroupsOutput .Reset ()
87+ e .DescribeSubnetsBehavior .Reset ()
88+ e .DescribeSecurityGroupsBehavior .Reset ()
8889 e .DescribeInstanceTypesOutput .Reset ()
8990 e .DescribeInstanceTypeOfferingsOutput .Reset ()
9091 e .DescribeAvailabilityZonesOutput .Reset ()
@@ -379,107 +380,109 @@ func (e *EC2API) DeleteLaunchTemplate(_ context.Context, input *ec2.DeleteLaunch
379380}
380381
381382func (e * EC2API ) DescribeSubnets (_ context.Context , input * ec2.DescribeSubnetsInput , _ ... func (* ec2.Options )) (* ec2.DescribeSubnetsOutput , error ) {
382- if ! e .NextError .IsNil () {
383- defer e .NextError .Reset ()
384- return nil , e .NextError .Get ()
385- }
386- if ! e .DescribeSubnetsOutput .IsNil () {
387- describeSubnetsOutput := e .DescribeSubnetsOutput .Clone ()
388- describeSubnetsOutput .Subnets = FilterDescribeSubnets (describeSubnetsOutput .Subnets , input .Filters )
389- return describeSubnetsOutput , nil
390- }
391- subnets := []ec2types.Subnet {
392- {
393- SubnetId : aws .String ("subnet-test1" ),
394- AvailabilityZone : aws .String ("test-zone-1a" ),
395- AvailabilityZoneId : aws .String ("tstz1-1a" ),
396- AvailableIpAddressCount : aws .Int32 (100 ),
397- MapPublicIpOnLaunch : aws .Bool (false ),
398- Tags : []ec2types.Tag {
399- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
400- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
383+ return e .DescribeSubnetsBehavior .Invoke (input , func (input * ec2.DescribeSubnetsInput ) (* ec2.DescribeSubnetsOutput , error ) {
384+ output := & ec2.DescribeSubnetsOutput {}
385+ e .Subnets .Range (func (key , value any ) bool {
386+ subnet := value .(ec2types.Subnet )
387+ if lo .Contains (input .SubnetIds , lo .FromPtr (subnet .SubnetId )) || len (input .Filters ) != 0 && len (FilterDescribeSubnets ([]ec2types.Subnet {subnet }, input .Filters )) != 0 {
388+ output .Subnets = append (output .Subnets , subnet )
389+ }
390+ return true
391+ })
392+ if len (output .Subnets ) != 0 {
393+ return output , nil
394+ }
395+
396+ defaultSubnets := []ec2types.Subnet {
397+ {
398+ SubnetId : aws .String ("subnet-test1" ),
399+ AvailabilityZone : aws .String ("test-zone-1a" ),
400+ AvailabilityZoneId : aws .String ("tstz1-1a" ),
401+ AvailableIpAddressCount : aws .Int32 (100 ),
402+ MapPublicIpOnLaunch : aws .Bool (false ),
403+ Tags : []ec2types.Tag {
404+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
405+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
406+ },
407+ VpcId : aws .String ("vpc-test1" ),
401408 },
402- },
403- {
404- SubnetId : aws .String ("subnet-test2" ),
405- AvailabilityZone : aws .String ("test-zone-1b" ),
406- AvailabilityZoneId : aws .String ("tstz1-1b" ),
407- AvailableIpAddressCount : aws .Int32 (100 ),
408- MapPublicIpOnLaunch : aws .Bool (true ),
409- Tags : []ec2types.Tag {
410- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
411- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
409+ {
410+ SubnetId : aws .String ("subnet-test2" ),
411+ AvailabilityZone : aws .String ("test-zone-1b" ),
412+ AvailabilityZoneId : aws .String ("tstz1-1b" ),
413+ AvailableIpAddressCount : aws .Int32 (100 ),
414+ MapPublicIpOnLaunch : aws .Bool (true ),
415+ Tags : []ec2types.Tag {
416+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
417+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
418+ },
419+ VpcId : aws .String ("vpc-test1" ),
412420 },
413- },
414- {
415- SubnetId : aws .String ("subnet-test3" ),
416- AvailabilityZone : aws .String ("test-zone-1c" ),
417- AvailabilityZoneId : aws .String ("tstz1-1c" ),
418- AvailableIpAddressCount : aws .Int32 (100 ),
419- Tags : []ec2types.Tag {
420- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
421- {Key : aws .String ("TestTag" )},
422- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
421+ {
422+ SubnetId : aws .String ("subnet-test3" ),
423+ AvailabilityZone : aws .String ("test-zone-1c" ),
424+ AvailabilityZoneId : aws .String ("tstz1-1c" ),
425+ AvailableIpAddressCount : aws .Int32 (100 ),
426+ Tags : []ec2types.Tag {
427+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
428+ {Key : aws .String ("TestTag" )},
429+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
430+ },
431+ VpcId : aws .String ("vpc-test1" ),
423432 },
424- },
425- {
426- SubnetId : aws .String ("subnet-test4" ),
427- AvailabilityZone : aws .String ("test-zone-1a-local" ),
428- AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
429- AvailableIpAddressCount : aws .Int32 (100 ),
430- MapPublicIpOnLaunch : aws .Bool (true ),
431- Tags : []ec2types.Tag {
432- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
433+ {
434+ SubnetId : aws .String ("subnet-test4" ),
435+ AvailabilityZone : aws .String ("test-zone-1a-local" ),
436+ AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
437+ AvailableIpAddressCount : aws .Int32 (100 ),
438+ MapPublicIpOnLaunch : aws .Bool (true ),
439+ Tags : []ec2types.Tag {
440+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
441+ },
442+ VpcId : aws .String ("vpc-test1" ),
433443 },
434- },
435- }
436- if len ( input . Filters ) == 0 {
437- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
438- }
439- return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( subnets , input . Filters )}, nil
444+ }
445+ if len ( input . Filters ) == 0 {
446+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
447+ }
448+ return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( defaultSubnets , input . Filters )}, nil
449+ })
440450}
441451
442452func (e * EC2API ) DescribeSecurityGroups (_ context.Context , input * ec2.DescribeSecurityGroupsInput , _ ... func (* ec2.Options )) (* ec2.DescribeSecurityGroupsOutput , error ) {
443- if ! e .NextError .IsNil () {
444- defer e .NextError .Reset ()
445- return nil , e .NextError .Get ()
446- }
447- if ! e .DescribeSecurityGroupsOutput .IsNil () {
448- describeSecurityGroupsOutput := e .DescribeSecurityGroupsOutput .Clone ()
449- describeSecurityGroupsOutput .SecurityGroups = FilterDescribeSecurtyGroups (describeSecurityGroupsOutput .SecurityGroups , input .Filters )
450- return e .DescribeSecurityGroupsOutput .Clone (), nil
451- }
452- sgs := []ec2types.SecurityGroup {
453- {
454- GroupId : aws .String ("sg-test1" ),
455- GroupName : aws .String ("securityGroup-test1" ),
456- Tags : []ec2types.Tag {
457- {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
458- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
453+ return e .DescribeSecurityGroupsBehavior .Invoke (input , func (input * ec2.DescribeSecurityGroupsInput ) (* ec2.DescribeSecurityGroupsOutput , error ) {
454+ defaultSecurityGroups := []ec2types.SecurityGroup {
455+ {
456+ GroupId : aws .String ("sg-test1" ),
457+ GroupName : aws .String ("securityGroup-test1" ),
458+ Tags : []ec2types.Tag {
459+ {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
460+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
461+ },
459462 },
460- },
461- {
462- GroupId : aws .String ("sg -test2" ),
463- GroupName : aws . String ( "securityGroup-test2" ),
464- Tags : []ec2types. Tag {
465- {Key : aws .String ("Name " ), Value : aws .String ("test-security-group-2 " )},
466- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
463+ {
464+ GroupId : aws . String ( "sg-test2" ),
465+ GroupName : aws .String ("securityGroup -test2" ),
466+ Tags : []ec2types. Tag {
467+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-2" )},
468+ {Key : aws .String ("foo " ), Value : aws .String ("bar " )},
469+ },
467470 },
468- },
469- {
470- GroupId : aws .String ("sg -test3" ),
471- GroupName : aws . String ( "securityGroup-test3" ),
472- Tags : []ec2types. Tag {
473- {Key : aws .String ("Name" ), Value : aws . String ( "test-security-group-3 " )},
474- {Key : aws .String ("TestTag " )},
475- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
471+ {
472+ GroupId : aws . String ( "sg-test3" ),
473+ GroupName : aws .String ("securityGroup -test3" ),
474+ Tags : []ec2types. Tag {
475+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-3" )},
476+ {Key : aws .String ("TestTag " )},
477+ {Key : aws .String ("foo" ), Value : aws . String ( "bar " )},
478+ },
476479 },
477- },
478- }
479- if len ( input . Filters ) == 0 {
480- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
481- }
482- return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( sgs , input . Filters )}, nil
480+ }
481+ if len ( input . Filters ) == 0 {
482+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
483+ }
484+ return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( defaultSecurityGroups , input . Filters )}, nil
485+ })
483486}
484487
485488func (e * EC2API ) DescribeAvailabilityZones (context.Context , * ec2.DescribeAvailabilityZonesInput , ... func (* ec2.Options )) (* ec2.DescribeAvailabilityZonesOutput , error ) {
0 commit comments