@@ -28,6 +28,7 @@ func setupAWSMocks() {
2828 MaxSize : aws .Int64 (int64 (25 )),
2929 DesiredCapacity : aws .Int64 (int64 (1 )),
3030 VPCZoneIdentifier : aws .String ("subnetID-1,subnetID-2" ),
31+ Tags : []* autoscaling.TagDescription {},
3132 }
3233
3334 mockAWSConfig = cloudprovider.AWSNodeGroupConfig {
@@ -36,6 +37,7 @@ func setupAWSMocks() {
3637 FleetInstanceReadyTimeout : tickerTimeout ,
3738 Lifecycle : LifecycleOnDemand ,
3839 InstanceTypeOverrides : []string {"instance-1" , "instance-2" },
40+ ResourceTagging : false ,
3941 }
4042
4143 mockNodeGroup = NodeGroup {
@@ -128,6 +130,29 @@ func TestCreateFleetInput(t *testing.T) {
128130 }
129131}
130132
133+ func TestCreateFleetInput_WithResourceTagging (t * testing.T ) {
134+ setupAWSMocks ()
135+ autoScalingGroups := []* autoscaling.Group {& mockASG }
136+ nodeGroups := map [string ]* NodeGroup {mockNodeGroup .id : & mockNodeGroup }
137+ addCount := int64 (2 )
138+
139+ awsCloudProvider , _ := newMockCloudProviderUsingInjection (
140+ nodeGroups ,
141+ & test.MockAutoscalingService {
142+ DescribeAutoScalingGroupsOutput : & autoscaling.DescribeAutoScalingGroupsOutput {
143+ AutoScalingGroups : autoScalingGroups ,
144+ },
145+ },
146+ & test.MockEc2Service {},
147+ )
148+ mockNodeGroup .provider = awsCloudProvider
149+ mockAWSConfig .ResourceTagging = true
150+ mockNodeGroupConfig .AWSConfig = mockAWSConfig
151+
152+ _ , err := createFleetInput (mockNodeGroup , addCount )
153+ assert .Nil (t , err , "Expected no error from createFleetInput" )
154+ }
155+
131156func TestCreateTemplateOverrides_FailedCall (t * testing.T ) {
132157 setupAWSMocks ()
133158 expectedError := errors .New ("call failed" )
@@ -234,3 +259,66 @@ func TestCreateTemplateOverrides_NoInstanceTypeOverrides_Success(t *testing.T) {
234259 _ , err := createTemplateOverrides (mockNodeGroup )
235260 assert .Nil (t , err , "Expected no error from createTemplateOverrides" )
236261}
262+ func TestAddASGTags_ResourceTaggingFalse (t * testing.T ) {
263+ setupAWSMocks ()
264+ mockNodeGroupConfig .AWSConfig .ResourceTagging = false
265+ awsCloudProvider , _ := newMockCloudProviderUsingInjection (
266+ nil ,
267+ & test.MockAutoscalingService {},
268+ & test.MockEc2Service {},
269+ )
270+ addASGTags (& mockNodeGroupConfig , & mockASG , awsCloudProvider )
271+ }
272+
273+ func TestAddASGTags_ResourceTaggingTrue (t * testing.T ) {
274+ setupAWSMocks ()
275+ mockNodeGroupConfig .AWSConfig .ResourceTagging = true
276+
277+ // Mock service call
278+ awsCloudProvider , _ := newMockCloudProviderUsingInjection (
279+ nil ,
280+ & test.MockAutoscalingService {
281+ CreateOrUpdateTagsOutput : & autoscaling.CreateOrUpdateTagsOutput {},
282+ },
283+ & test.MockEc2Service {},
284+ )
285+ addASGTags (& mockNodeGroupConfig , & mockASG , awsCloudProvider )
286+ }
287+
288+ func TestAddASGTags_ASGAlreadyTagged (t * testing.T ) {
289+ setupAWSMocks ()
290+ mockNodeGroupConfig .AWSConfig .ResourceTagging = true
291+
292+ // Mock existing tags
293+ key := tagKey
294+ asgTag := autoscaling.TagDescription {
295+ Key : & key ,
296+ }
297+ mockASG .Tags = append (mockASG .Tags , & asgTag )
298+
299+ // Mock service call
300+ awsCloudProvider , _ := newMockCloudProviderUsingInjection (
301+ nil ,
302+ & test.MockAutoscalingService {
303+ CreateOrUpdateTagsOutput : & autoscaling.CreateOrUpdateTagsOutput {},
304+ },
305+ & test.MockEc2Service {},
306+ )
307+ addASGTags (& mockNodeGroupConfig , & mockASG , awsCloudProvider )
308+ }
309+
310+ func TestAddASGTags_WithErrorResponse (t * testing.T ) {
311+ setupAWSMocks ()
312+ mockNodeGroupConfig .AWSConfig .ResourceTagging = true
313+
314+ // Mock service call and error
315+ awsCloudProvider , _ := newMockCloudProviderUsingInjection (
316+ nil ,
317+ & test.MockAutoscalingService {
318+ CreateOrUpdateTagsOutput : & autoscaling.CreateOrUpdateTagsOutput {},
319+ CreateOrUpdateTagsErr : errors .New ("unauthorized" ),
320+ },
321+ & test.MockEc2Service {},
322+ )
323+ addASGTags (& mockNodeGroupConfig , & mockASG , awsCloudProvider )
324+ }
0 commit comments