@@ -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 ]
@@ -61,6 +61,7 @@ type EC2Behavior struct {
6161 CreateTagsBehavior MockedFunction [ec2.CreateTagsInput , ec2.CreateTagsOutput ]
6262 CalledWithCreateLaunchTemplateInput AtomicPtrSlice [ec2.CreateLaunchTemplateInput ]
6363 CalledWithDescribeImagesInput AtomicPtrSlice [ec2.DescribeImagesInput ]
64+ Subnets sync.Map
6465 Instances sync.Map
6566 LaunchTemplates sync.Map
6667 InsufficientCapacityPools atomic.Slice [CapacityPool ]
@@ -84,8 +85,8 @@ var DefaultSupportedUsageClasses = aws.StringSlice([]string{"on-demand", "spot"}
8485func (e * EC2API ) Reset () {
8586 e .DescribeImagesOutput .Reset ()
8687 e .DescribeLaunchTemplatesOutput .Reset ()
87- e .DescribeSubnetsOutput .Reset ()
88- e .DescribeSecurityGroupsOutput .Reset ()
88+ e .DescribeSubnetsBehavior .Reset ()
89+ e .DescribeSecurityGroupsBehavior .Reset ()
8990 e .DescribeInstanceTypesOutput .Reset ()
9091 e .DescribeInstanceTypeOfferingsOutput .Reset ()
9192 e .DescribeAvailabilityZonesOutput .Reset ()
@@ -405,107 +406,109 @@ func (e *EC2API) DeleteLaunchTemplateWithContext(_ context.Context, input *ec2.D
405406}
406407
407408func (e * EC2API ) DescribeSubnetsWithContext (_ context.Context , input * ec2.DescribeSubnetsInput , _ ... request.Option ) (* ec2.DescribeSubnetsOutput , error ) {
408- if ! e .NextError .IsNil () {
409- defer e .NextError .Reset ()
410- return nil , e .NextError .Get ()
411- }
412- if ! e .DescribeSubnetsOutput .IsNil () {
413- describeSubnetsOutput := e .DescribeSubnetsOutput .Clone ()
414- describeSubnetsOutput .Subnets = FilterDescribeSubnets (describeSubnetsOutput .Subnets , input .Filters )
415- return describeSubnetsOutput , nil
416- }
417- subnets := []* ec2.Subnet {
418- {
419- SubnetId : aws .String ("subnet-test1" ),
420- AvailabilityZone : aws .String ("test-zone-1a" ),
421- AvailabilityZoneId : aws .String ("tstz1-1a" ),
422- AvailableIpAddressCount : aws .Int64 (100 ),
423- MapPublicIpOnLaunch : aws .Bool (false ),
424- Tags : []* ec2.Tag {
425- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
426- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
409+ return e .DescribeSubnetsBehavior .Invoke (input , func (input * ec2.DescribeSubnetsInput ) (* ec2.DescribeSubnetsOutput , error ) {
410+ output := & ec2.DescribeSubnetsOutput {}
411+ e .Subnets .Range (func (key , value any ) bool {
412+ subnet := value .(* ec2.Subnet )
413+ if lo .Contains (lo .Map (input .SubnetIds , func (s * string , _ int ) string { return lo .FromPtr (s ) }), lo .FromPtr (subnet .SubnetId )) || len (input .Filters ) != 0 && len (FilterDescribeSubnets ([]* ec2.Subnet {subnet }, input .Filters )) != 0 {
414+ output .Subnets = append (output .Subnets , subnet )
415+ }
416+ return true
417+ })
418+ if len (output .Subnets ) != 0 {
419+ return output , nil
420+ }
421+
422+ defaultSubnets := []* ec2.Subnet {
423+ {
424+ SubnetId : aws .String ("subnet-test1" ),
425+ AvailabilityZone : aws .String ("test-zone-1a" ),
426+ AvailabilityZoneId : aws .String ("tstz1-1a" ),
427+ AvailableIpAddressCount : aws .Int64 (100 ),
428+ MapPublicIpOnLaunch : aws .Bool (false ),
429+ Tags : []* ec2.Tag {
430+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-1" )},
431+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
432+ },
433+ VpcId : aws .String ("vpc-test1" ),
427434 },
428- },
429- {
430- SubnetId : aws .String ("subnet-test2" ),
431- AvailabilityZone : aws .String ("test-zone-1b" ),
432- AvailabilityZoneId : aws .String ("tstz1-1b" ),
433- AvailableIpAddressCount : aws .Int64 (100 ),
434- MapPublicIpOnLaunch : aws .Bool (true ),
435- Tags : []* ec2.Tag {
436- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
437- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
435+ {
436+ SubnetId : aws .String ("subnet-test2" ),
437+ AvailabilityZone : aws .String ("test-zone-1b" ),
438+ AvailabilityZoneId : aws .String ("tstz1-1b" ),
439+ AvailableIpAddressCount : aws .Int64 (100 ),
440+ MapPublicIpOnLaunch : aws .Bool (true ),
441+ Tags : []* ec2.Tag {
442+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-2" )},
443+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
444+ },
445+ VpcId : aws .String ("vpc-test1" ),
438446 },
439- },
440- {
441- SubnetId : aws .String ("subnet-test3" ),
442- AvailabilityZone : aws .String ("test-zone-1c" ),
443- AvailabilityZoneId : aws .String ("tstz1-1c" ),
444- AvailableIpAddressCount : aws .Int64 (100 ),
445- Tags : []* ec2.Tag {
446- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
447- {Key : aws .String ("TestTag" )},
448- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
447+ {
448+ SubnetId : aws .String ("subnet-test3" ),
449+ AvailabilityZone : aws .String ("test-zone-1c" ),
450+ AvailabilityZoneId : aws .String ("tstz1-1c" ),
451+ AvailableIpAddressCount : aws .Int64 (100 ),
452+ Tags : []* ec2.Tag {
453+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-3" )},
454+ {Key : aws .String ("TestTag" )},
455+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
456+ },
457+ VpcId : aws .String ("vpc-test1" ),
449458 },
450- },
451- {
452- SubnetId : aws .String ("subnet-test4" ),
453- AvailabilityZone : aws .String ("test-zone-1a-local" ),
454- AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
455- AvailableIpAddressCount : aws .Int64 (100 ),
456- MapPublicIpOnLaunch : aws .Bool (true ),
457- Tags : []* ec2.Tag {
458- {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
459+ {
460+ SubnetId : aws .String ("subnet-test4" ),
461+ AvailabilityZone : aws .String ("test-zone-1a-local" ),
462+ AvailabilityZoneId : aws .String ("tstz1-1alocal" ),
463+ AvailableIpAddressCount : aws .Int64 (100 ),
464+ MapPublicIpOnLaunch : aws .Bool (true ),
465+ Tags : []* ec2.Tag {
466+ {Key : aws .String ("Name" ), Value : aws .String ("test-subnet-4" )},
467+ },
468+ VpcId : aws .String ("vpc-test1" ),
459469 },
460- },
461- }
462- if len ( input . Filters ) == 0 {
463- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
464- }
465- return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( subnets , input . Filters )}, nil
470+ }
471+ if len ( input . Filters ) == 0 {
472+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
473+ }
474+ return & ec2. DescribeSubnetsOutput { Subnets : FilterDescribeSubnets ( defaultSubnets , input . Filters )}, nil
475+ })
466476}
467477
468478func (e * EC2API ) DescribeSecurityGroupsWithContext (_ context.Context , input * ec2.DescribeSecurityGroupsInput , _ ... request.Option ) (* ec2.DescribeSecurityGroupsOutput , error ) {
469- if ! e .NextError .IsNil () {
470- defer e .NextError .Reset ()
471- return nil , e .NextError .Get ()
472- }
473- if ! e .DescribeSecurityGroupsOutput .IsNil () {
474- describeSecurityGroupsOutput := e .DescribeSecurityGroupsOutput .Clone ()
475- describeSecurityGroupsOutput .SecurityGroups = FilterDescribeSecurtyGroups (describeSecurityGroupsOutput .SecurityGroups , input .Filters )
476- return e .DescribeSecurityGroupsOutput .Clone (), nil
477- }
478- sgs := []* ec2.SecurityGroup {
479- {
480- GroupId : aws .String ("sg-test1" ),
481- GroupName : aws .String ("securityGroup-test1" ),
482- Tags : []* ec2.Tag {
483- {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
484- {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
479+ return e .DescribeSecurityGroupsBehavior .Invoke (input , func (input * ec2.DescribeSecurityGroupsInput ) (* ec2.DescribeSecurityGroupsOutput , error ) {
480+ defaultSecurityGroups := []* ec2.SecurityGroup {
481+ {
482+ GroupId : aws .String ("sg-test1" ),
483+ GroupName : aws .String ("securityGroup-test1" ),
484+ Tags : []* ec2.Tag {
485+ {Key : aws .String ("Name" ), Value : aws .String ("test-security-group-1" )},
486+ {Key : aws .String ("foo" ), Value : aws .String ("bar" )},
487+ },
485488 },
486- },
487- {
488- GroupId : aws .String ("sg -test2" ),
489- GroupName : aws . String ( "securityGroup-test2" ),
490- Tags : [] * ec2. Tag {
491- {Key : aws .String ("Name " ), Value : aws .String ("test-security-group-2 " )},
492- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
489+ {
490+ GroupId : aws . String ( "sg-test2" ),
491+ GroupName : aws .String ("securityGroup -test2" ),
492+ Tags : [] * ec2. Tag {
493+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-2" )},
494+ {Key : aws .String ("foo " ), Value : aws .String ("bar " )},
495+ },
493496 },
494- },
495- {
496- GroupId : aws .String ("sg -test3" ),
497- GroupName : aws . String ( "securityGroup-test3" ),
498- Tags : [] * ec2. Tag {
499- {Key : aws .String ("Name" ), Value : aws . String ( "test-security-group-3 " )},
500- {Key : aws .String ("TestTag " )},
501- { Key : aws . String ( "foo" ), Value : aws . String ( "bar" ) },
497+ {
498+ GroupId : aws . String ( "sg-test3" ),
499+ GroupName : aws .String ("securityGroup -test3" ),
500+ Tags : [] * ec2. Tag {
501+ { Key : aws . String ( "Name" ), Value : aws . String ( "test-security-group-3" )},
502+ {Key : aws .String ("TestTag " )},
503+ {Key : aws .String ("foo" ), Value : aws . String ( "bar " )},
504+ },
502505 },
503- },
504- }
505- if len ( input . Filters ) == 0 {
506- return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
507- }
508- return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( sgs , input . Filters )}, nil
506+ }
507+ if len ( input . Filters ) == 0 {
508+ return nil , fmt . Errorf ( "InvalidParameterValue: The filter 'null' is invalid" )
509+ }
510+ return & ec2. DescribeSecurityGroupsOutput { SecurityGroups : FilterDescribeSecurtyGroups ( defaultSecurityGroups , input . Filters )}, nil
511+ })
509512}
510513
511514func (e * EC2API ) DescribeAvailabilityZonesWithContext (context.Context , * ec2.DescribeAvailabilityZonesInput , ... request.Option ) (* ec2.DescribeAvailabilityZonesOutput , error ) {
0 commit comments