@@ -12,7 +12,7 @@ import (
1212 "testing"
1313 "time"
1414
15- "github.com/aws/aws-sdk-go/aws "
15+ "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types "
1616 "github.com/aws/aws-sdk-go/aws/ec2metadata"
1717 "github.com/aws/aws-sdk-go/aws/session"
1818 "github.com/jellydator/ttlcache/v3"
@@ -24,7 +24,6 @@ import (
2424
2525 "github.com/aws/amazon-cloudwatch-agent/internal/ec2metadataprovider"
2626 "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsentity/entityattributes"
27- "github.com/aws/amazon-cloudwatch-agent/sdk/service/cloudwatchlogs"
2827 "github.com/aws/amazon-cloudwatch-agent/translator/config"
2928)
3029
@@ -211,7 +210,7 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
211210 tests := []struct {
212211 name string
213212 fields fields
214- want map [string ]* string
213+ want map [string ]string
215214 }{
216215 {
217216 name : "HappyPath" ,
@@ -221,10 +220,10 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
221220 },
222221 mode : config .ModeEC2 ,
223222 },
224- want : map [string ]* string {
225- ASGKey : aws . String ( "ASG-1" ) ,
226- InstanceIDKey : aws . String ( "i-123456789" ) ,
227- PlatformType : aws . String ( EC2PlatForm ) ,
223+ want : map [string ]string {
224+ ASGKey : "ASG-1" ,
225+ InstanceIDKey : "i-123456789" ,
226+ PlatformType : EC2PlatForm ,
228227 },
229228 },
230229 {
@@ -236,9 +235,9 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
236235 mode : config .ModeEC2 ,
237236 emptyASG : true ,
238237 },
239- want : map [string ]* string {
240- InstanceIDKey : aws . String ( "i-123456789" ) ,
241- PlatformType : aws . String ( EC2PlatForm ) ,
238+ want : map [string ]string {
239+ InstanceIDKey : "i-123456789" ,
240+ PlatformType : EC2PlatForm ,
242241 },
243242 },
244243 {
@@ -247,8 +246,8 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
247246 mode : config .ModeEC2 ,
248247 emptyASG : true ,
249248 },
250- want : map [string ]* string {
251- PlatformType : aws . String ( EC2PlatForm ) ,
249+ want : map [string ]string {
250+ PlatformType : EC2PlatForm ,
252251 },
253252 },
254253 {
@@ -259,7 +258,7 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
259258 },
260259 mode : config .ModeOnPrem ,
261260 },
262- want : map [string ]* string {},
261+ want : map [string ]string {},
263262 },
264263 }
265264 for _ , tt := range tests {
@@ -275,7 +274,7 @@ func TestEntityStore_createAttributeMaps(t *testing.T) {
275274 sp .On ("getAutoScalingGroup" ).Return ("ASG-1" )
276275 }
277276 e .serviceprovider = sp
278- assert .Equalf (t , dereferenceMap ( tt .want ), dereferenceMap ( e .createAttributeMap () ), "createAttributeMap()" )
277+ assert .Equalf (t , tt .want , e .createAttributeMap (), "createAttributeMap()" )
279278 })
280279 }
281280}
@@ -284,38 +283,38 @@ func TestEntityStore_createServiceKeyAttributes(t *testing.T) {
284283 tests := []struct {
285284 name string
286285 serviceAttr ServiceAttribute
287- want map [string ]* string
286+ want map [string ]string
288287 }{
289288 {
290289 name : "NameAndEnvironmentSet" ,
291290 serviceAttr : ServiceAttribute {ServiceName : "test-service" , Environment : "test-environment" },
292- want : map [string ]* string {
293- entityattributes .DeploymentEnvironment : aws . String ( "test-environment" ) ,
294- entityattributes .ServiceName : aws . String ( "test-service" ) ,
295- entityattributes .EntityType : aws . String ( Service ) ,
291+ want : map [string ]string {
292+ entityattributes .DeploymentEnvironment : "test-environment" ,
293+ entityattributes .ServiceName : "test-service" ,
294+ entityattributes .EntityType : Service ,
296295 },
297296 },
298297 {
299298 name : "OnlyNameSet" ,
300299 serviceAttr : ServiceAttribute {ServiceName : "test-service" },
301- want : map [string ]* string {
302- entityattributes .ServiceName : aws . String ( "test-service" ) ,
303- entityattributes .EntityType : aws . String ( Service ) ,
300+ want : map [string ]string {
301+ entityattributes .ServiceName : "test-service" ,
302+ entityattributes .EntityType : Service ,
304303 },
305304 },
306305 {
307306 name : "OnlyEnvironmentSet" ,
308307 serviceAttr : ServiceAttribute {Environment : "test-environment" },
309- want : map [string ]* string {
310- entityattributes .DeploymentEnvironment : aws . String ( "test-environment" ) ,
311- entityattributes .EntityType : aws . String ( Service ) ,
308+ want : map [string ]string {
309+ entityattributes .DeploymentEnvironment : "test-environment" ,
310+ entityattributes .EntityType : Service ,
312311 },
313312 },
314313 }
315314 for _ , tt := range tests {
316315 t .Run (tt .name , func (t * testing.T ) {
317316 e := & EntityStore {}
318- assert .Equalf (t , dereferenceMap ( tt .want ), dereferenceMap ( e .createServiceKeyAttributes (tt .serviceAttr ) ), "createServiceKeyAttributes()" )
317+ assert .Equalf (t , tt .want , e .createServiceKeyAttributes (tt .serviceAttr ), "createServiceKeyAttributes()" )
319318 })
320319 }
321320}
@@ -342,22 +341,22 @@ func TestEntityStore_createLogFileRID(t *testing.T) {
342341
343342 entity := e .CreateLogFileEntity (glob , group )
344343
345- expectedEntity := cloudwatchlogs .Entity {
346- KeyAttributes : map [string ]* string {
347- entityattributes .DeploymentEnvironment : aws . String ( "test-environment" ) ,
348- entityattributes .ServiceName : aws . String ( "test-service" ) ,
349- entityattributes .EntityType : aws . String ( Service ) ,
350- entityattributes .AwsAccountId : aws . String ( accountId ) ,
344+ expectedEntity := types .Entity {
345+ KeyAttributes : map [string ]string {
346+ entityattributes .DeploymentEnvironment : "test-environment" ,
347+ entityattributes .ServiceName : "test-service" ,
348+ entityattributes .EntityType : Service ,
349+ entityattributes .AwsAccountId : accountId ,
351350 },
352- Attributes : map [string ]* string {
353- InstanceIDKey : aws . String ( instanceId ) ,
354- ServiceNameSourceKey : aws . String ( ServiceNameSourceUserConfiguration ) ,
355- PlatformType : aws . String ( EC2PlatForm ) ,
356- entityattributes .AutoscalingGroup : aws . String ( "ASG-1" ) ,
351+ Attributes : map [string ]string {
352+ InstanceIDKey : instanceId ,
353+ ServiceNameSourceKey : ServiceNameSourceUserConfiguration ,
354+ PlatformType : EC2PlatForm ,
355+ entityattributes .AutoscalingGroup : "ASG-1" ,
357356 },
358357 }
359- assert .Equal (t , dereferenceMap ( expectedEntity .KeyAttributes ), dereferenceMap ( entity .KeyAttributes ) )
360- assert .Equal (t , dereferenceMap ( expectedEntity .Attributes ), dereferenceMap ( entity .Attributes ) )
358+ assert .Equal (t , expectedEntity .KeyAttributes , entity .KeyAttributes )
359+ assert .Equal (t , expectedEntity .Attributes , entity .Attributes )
361360}
362361
363362func TestEntityStore_createLogFileRID_ServiceProviderIsEmpty (t * testing.T ) {
@@ -375,18 +374,6 @@ func TestEntityStore_createLogFileRID_ServiceProviderIsEmpty(t *testing.T) {
375374 assert .Nil (t , entity )
376375}
377376
378- func dereferenceMap (input map [string ]* string ) map [string ]string {
379- result := make (map [string ]string )
380- for k , v := range input {
381- if v != nil {
382- result [k ] = * v
383- } else {
384- result [k ] = ""
385- }
386- }
387- return result
388- }
389-
390377func TestEntityStore_addServiceAttrEntryForLogFile (t * testing.T ) {
391378 sp := new (mockServiceProvider )
392379 e := EntityStore {serviceprovider : sp }
0 commit comments