@@ -259,7 +259,7 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
259
259
260
260
t .Run ("ProcessBatchOnLimit" , func (t * testing.T ) {
261
261
mockService := new (mockLogsService )
262
-
262
+
263
263
// Setup mock to expect a batch of 50 log groups
264
264
mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
265
265
return len (input .LogGroupIdentifiers ) == logGroupIdentifierLimit
@@ -269,7 +269,7 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
269
269
270
270
manager := NewTargetManager (logger , mockService )
271
271
tm := manager .(* targetManager )
272
-
272
+
273
273
for i := 0 ; i < logGroupIdentifierLimit ; i ++ {
274
274
target := Target {
275
275
Group : fmt .Sprintf ("group-%d" , i ),
@@ -278,15 +278,15 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
278
278
}
279
279
tm .dlg <- target
280
280
}
281
-
281
+
282
282
time .Sleep (100 * time .Millisecond )
283
-
283
+
284
284
mockService .AssertExpectations (t )
285
285
})
286
286
287
287
t .Run ("ProcessBatchOnTimer" , func (t * testing.T ) {
288
288
mockService := new (mockLogsService )
289
-
289
+
290
290
// Setup mock to expect a batch of less than 50 log groups
291
291
mockService .On ("DescribeLogGroups" , mock .MatchedBy (func (input * cloudwatchlogs.DescribeLogGroupsInput ) bool {
292
292
return len (input .LogGroupIdentifiers ) == 5
@@ -296,7 +296,7 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
296
296
297
297
manager := NewTargetManager (logger , mockService )
298
298
tm := manager .(* targetManager )
299
-
299
+
300
300
for i := 0 ; i < 5 ; i ++ {
301
301
target := Target {
302
302
Group : fmt .Sprintf ("group-%d" , i ),
@@ -305,16 +305,16 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
305
305
}
306
306
tm .dlg <- target
307
307
}
308
-
308
+
309
309
// Wait for ticker to fire (slightly longer than 5 seconds)
310
310
time .Sleep (5100 * time .Millisecond )
311
-
311
+
312
312
mockService .AssertExpectations (t )
313
313
})
314
314
315
315
t .Run ("ProcessBatchInvalidGroups" , func (t * testing.T ) {
316
316
mockService := new (mockLogsService )
317
-
317
+
318
318
// Return empty result
319
319
mockService .On ("DescribeLogGroups" , mock .Anything ).Return (& cloudwatchlogs.DescribeLogGroupsOutput {
320
320
LogGroups : []* cloudwatchlogs.LogGroup {},
@@ -333,10 +333,10 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
333
333
334
334
mockService .AssertNotCalled (t , "PutRetentionPolicy" )
335
335
})
336
-
336
+
337
337
t .Run ("RetentionPolicyUpdate" , func (t * testing.T ) {
338
338
mockService := new (mockLogsService )
339
-
339
+
340
340
mockService .On ("DescribeLogGroups" , mock .Anything ).Return (& cloudwatchlogs.DescribeLogGroupsOutput {
341
341
LogGroups : []* cloudwatchlogs.LogGroup {
342
342
{
@@ -349,29 +349,29 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
349
349
},
350
350
},
351
351
}, nil ).Once ()
352
-
352
+
353
353
// Setup mock for PutRetentionPolicy (should only be called for group-1)
354
354
mockService .On ("PutRetentionPolicy" , mock .MatchedBy (func (input * cloudwatchlogs.PutRetentionPolicyInput ) bool {
355
355
return * input .LogGroupName == "group-1" && * input .RetentionInDays == 7
356
356
})).Return (& cloudwatchlogs.PutRetentionPolicyOutput {}, nil ).Once ()
357
357
358
358
manager := NewTargetManager (logger , mockService )
359
359
tm := manager .(* targetManager )
360
-
360
+
361
361
// Create a batch with two targets, one needing retention update
362
362
batch := make (map [string ]Target )
363
363
batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
364
364
batch ["group-2" ] = Target {Group : "group-2" , Stream : "stream" , Retention : 7 }
365
-
365
+
366
366
tm .updateTargetBatch (batch )
367
367
time .Sleep (100 * time .Millisecond )
368
-
368
+
369
369
mockService .AssertExpectations (t )
370
370
})
371
-
371
+
372
372
t .Run ("BatchRetryOnError" , func (t * testing.T ) {
373
373
mockService := new (mockLogsService )
374
-
374
+
375
375
// Setup mock to fail once then succeed
376
376
mockService .On ("DescribeLogGroups" , mock .Anything ).
377
377
Return (& cloudwatchlogs.DescribeLogGroupsOutput {}, fmt .Errorf ("internal error" )).Once ()
@@ -382,15 +382,15 @@ func TestDescribeLogGroupsBatching(t *testing.T) {
382
382
383
383
manager := NewTargetManager (logger , mockService )
384
384
tm := manager .(* targetManager )
385
-
385
+
386
386
// Create a batch with one target
387
387
batch := make (map [string ]Target )
388
388
batch ["group-1" ] = Target {Group : "group-1" , Stream : "stream" , Retention : 7 }
389
-
389
+
390
390
tm .updateTargetBatch (batch )
391
391
// Sleep enough for retry
392
392
time .Sleep (2 * time .Second )
393
-
393
+
394
394
mockService .AssertExpectations (t )
395
395
})
396
396
}
0 commit comments