@@ -48,8 +48,8 @@ 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 ]
51+ DescribeSubnetsBehavior MockedFunction [ec2. DescribeSubnetsInput , ec2.DescribeSubnetsOutput ]
52+ DescribeSecurityGroupsBehavior MockedFunction [ec2. DescribeSecurityGroupsInput , ec2.DescribeSecurityGroupsOutput ]
5353 DescribeInstanceTypesOutput AtomicPtr [ec2.DescribeInstanceTypesOutput ]
5454 DescribeInstanceTypeOfferingsOutput AtomicPtr [ec2.DescribeInstanceTypeOfferingsOutput ]
5555 DescribeAvailabilityZonesOutput AtomicPtr [ec2.DescribeAvailabilityZonesOutput ]
@@ -60,6 +60,7 @@ type EC2Behavior struct {
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 ()
@@ -380,107 +381,109 @@ func (e *EC2API) DeleteLaunchTemplate(_ context.Context, input *ec2.DeleteLaunch
380381}
381382
382383func (e * EC2API ) DescribeSubnets (_ context.Context , input * ec2.DescribeSubnetsInput , _ ... func (* ec2.Options )) (* ec2.DescribeSubnetsOutput , error ) {
383- if ! e .NextError .IsNil () {
384- defer e .NextError .Reset ()
385- return nil , e .NextError .Get ()
386- }
387- if ! e .DescribeSubnetsOutput .IsNil () {
388- describeSubnetsOutput := e .DescribeSubnetsOutput .Clone ()
389- describeSubnetsOutput .Subnets = FilterDescribeSubnets (describeSubnetsOutput .Subnets , input .Filters )
390- return describeSubnetsOutput , nil
391- }
392- subnets := []ec2types.Subnet {
393- {
394- SubnetId : aws .String ("subnet-test1" ),
395- AvailabilityZone : aws .String ("test-zone-1a" ),
396- AvailabilityZoneId : aws .String ("tstz1-1a" ),
397- AvailableIpAddressCount : aws .Int32 (100 ),
398- MapPublicIpOnLaunch : aws .Bool (false ),
399- Tags : []ec2types.Tag {
400- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
401- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
384+ return e .DescribeSubnetsBehavior .Invoke (input , func (input * ec2.DescribeSubnetsInput ) (* ec2.DescribeSubnetsOutput , error ) {
385+ output := & ec2.DescribeSubnetsOutput {}
386+ e .Subnets .Range (func (key , value any ) bool {
387+ subnet := value .(ec2types.Subnet )
388+ if lo .Contains (input .SubnetIds , lo .FromPtr (subnet .SubnetId )) || len (input .Filters ) != 0 && len (FilterDescribeSubnets ([]ec2types.Subnet {subnet }, input .Filters )) != 0 {
389+ output .Subnets = append (output .Subnets , subnet )
390+ }
391+ return true
392+ })
393+ if len (output .Subnets ) != 0 {
394+ return output , nil
395+ }
396+
397+ defaultSubnets := []ec2types.Subnet {
398+ {
399+ SubnetId : aws .String ("subnet-test1" ),
400+ AvailabilityZone : aws .String ("test-zone-1a" ),
401+ AvailabilityZoneId : aws .String ("tstz1-1a" ),
402+ AvailableIpAddressCount : aws .Int32 (100 ),
403+ MapPublicIpOnLaunch : aws .Bool (false ),
404+ Tags : []ec2types.Tag {
405+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
406+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
407+ },
408+ VpcId : aws .String ("vpc-test1" ),
402409 },
403- },
404- {
405- SubnetId : aws .String ("subnet-test2" ),
406- AvailabilityZone : aws .String ("test-zone-1b" ),
407- AvailabilityZoneId : aws .String ("tstz1-1b" ),
408- AvailableIpAddressCount : aws .Int32 (100 ),
409- MapPublicIpOnLaunch : aws .Bool (true ),
410- Tags : []ec2types.Tag {
411- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
412- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
410+ {
411+ SubnetId : aws .String ("subnet-test2" ),
412+ AvailabilityZone : aws .String ("test-zone-1b" ),
413+ AvailabilityZoneId : aws .String ("tstz1-1b" ),
414+ AvailableIpAddressCount : aws .Int32 (100 ),
415+ MapPublicIpOnLaunch : aws .Bool (true ),
416+ Tags : []ec2types.Tag {
417+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
418+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
419+ },
420+ VpcId : aws .String ("vpc-test1" ),
413421 },
414- },
415- {
416- SubnetId : aws .String ("subnet-test3" ),
417- AvailabilityZone : aws .String ("test-zone-1c" ),
418- AvailabilityZoneId : aws .String ("tstz1-1c" ),
419- AvailableIpAddressCount : aws .Int32 (100 ),
420- Tags : []ec2types.Tag {
421- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
422- {Key : aws .String ("TestTag" )},
423- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
422+ {
423+ SubnetId : aws .String ("subnet-test3" ),
424+ AvailabilityZone : aws .String ("test-zone-1c" ),
425+ AvailabilityZoneId : aws .String ("tstz1-1c" ),
426+ AvailableIpAddressCount : aws .Int32 (100 ),
427+ Tags : []ec2types.Tag {
428+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
429+ {Key : aws .String ("TestTag" )},
430+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
431+ },
432+ VpcId : aws .String ("vpc-test1" ),
424433 },
425- },
426- {
427- SubnetId : aws .String ("subnet-test4" ),
428- AvailabilityZone : aws .String ("test-zone-1a-local" ),
429- AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
430- AvailableIpAddressCount : aws .Int32 (100 ),
431- MapPublicIpOnLaunch : aws .Bool (true ),
432- Tags : []ec2types.Tag {
433- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
434+ {
435+ SubnetId : aws .String ("subnet-test4" ),
436+ AvailabilityZone : aws .String ("test-zone-1a-local" ),
437+ AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
438+ AvailableIpAddressCount : aws .Int32 (100 ),
439+ MapPublicIpOnLaunch : aws .Bool (true ),
440+ Tags : []ec2types.Tag {
441+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
442+ },
443+ VpcId : aws .String ("vpc-test1" ),
434444 },
435- },
436- }
437- if len ( input . Filters ) == 0 {
438- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
439- }
440- return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( subnets , input . Filters )}, nil
445+ }
446+ if len ( input . Filters ) == 0 {
447+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
448+ }
449+ return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( defaultSubnets , input . Filters )}, nil
450+ })
441451}
442452
443453func (e * EC2API ) DescribeSecurityGroups (_ context.Context , input * ec2.DescribeSecurityGroupsInput , _ ... func (* ec2.Options )) (* ec2.DescribeSecurityGroupsOutput , error ) {
444- if ! e .NextError .IsNil () {
445- defer e .NextError .Reset ()
446- return nil , e .NextError .Get ()
447- }
448- if ! e .DescribeSecurityGroupsOutput .IsNil () {
449- describeSecurityGroupsOutput := e .DescribeSecurityGroupsOutput .Clone ()
450- describeSecurityGroupsOutput .SecurityGroups = FilterDescribeSecurtyGroups (describeSecurityGroupsOutput .SecurityGroups , input .Filters )
451- return e .DescribeSecurityGroupsOutput .Clone (), nil
452- }
453- sgs := []ec2types.SecurityGroup {
454- {
455- GroupId : aws .String ("sg-test1" ),
456- GroupName : aws .String ("securityGroup-test1" ),
457- Tags : []ec2types.Tag {
458- {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
459- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
454+ return e .DescribeSecurityGroupsBehavior .Invoke (input , func (input * ec2.DescribeSecurityGroupsInput ) (* ec2.DescribeSecurityGroupsOutput , error ) {
455+ defaultSecurityGroups := []ec2types.SecurityGroup {
456+ {
457+ GroupId : aws .String ("sg-test1" ),
458+ GroupName : aws .String ("securityGroup-test1" ),
459+ Tags : []ec2types.Tag {
460+ {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
461+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
462+ },
460463 },
461- },
462- {
463- GroupId : aws .String ("sg -test2" ),
464- GroupName : aws . String ( "securityGroup-test2" ),
465- Tags : []ec2types. Tag {
466- {Key : aws .String ("Name " ), Value : aws .String ("test-security-group-2 " )},
467- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
464+ {
465+ GroupId : aws . String ( "sg-test2" ),
466+ GroupName : aws .String ("securityGroup -test2" ),
467+ Tags : []ec2types. Tag {
468+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-2" )},
469+ {Key : aws .String ("foo " ), Value : aws .String ("bar " )},
470+ },
468471 },
469- },
470- {
471- GroupId : aws .String ("sg -test3" ),
472- GroupName : aws . String ( "securityGroup-test3" ),
473- Tags : []ec2types. Tag {
474- {Key : aws .String ("Name" ), Value : aws . String ( "test-security-group-3 " )},
475- {Key : aws .String ("TestTag " )},
476- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
472+ {
473+ GroupId : aws . String ( "sg-test3" ),
474+ GroupName : aws .String ("securityGroup -test3" ),
475+ Tags : []ec2types. Tag {
476+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-3" )},
477+ {Key : aws .String ("TestTag " )},
478+ {Key : aws .String ("foo" ), Value : aws . String ( "bar " )},
479+ },
477480 },
478- },
479- }
480- if len ( input . Filters ) == 0 {
481- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
482- }
483- return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( sgs , input . Filters )}, nil
481+ }
482+ if len ( input . Filters ) == 0 {
483+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
484+ }
485+ return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( defaultSecurityGroups , input . Filters )}, nil
486+ })
484487}
485488
486489func (e * EC2API ) DescribeAvailabilityZones (context.Context , * ec2.DescribeAvailabilityZonesInput , ... func (* ec2.Options )) (* ec2.DescribeAvailabilityZonesOutput , error ) {
0 commit comments