@@ -12,9 +12,8 @@ import (
1212 "testing"
1313 "time"
1414
15+ "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
1516 "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
16- "github.com/aws/aws-sdk-go/aws/ec2metadata"
17- "github.com/aws/aws-sdk-go/aws/session"
1817 "github.com/jellydator/ttlcache/v3"
1918 "github.com/stretchr/testify/assert"
2019 "github.com/stretchr/testify/mock"
@@ -73,57 +72,59 @@ func (s *mockServiceProvider) setAutoScalingGroup(asg string) {
7372}
7473
7574type mockMetadataProvider struct {
76- InstanceIdentityDocument * ec2metadata. EC2InstanceIdentityDocument
75+ InstanceIdentityDocument * imds. InstanceIdentityDocument
7776 Tags map [string ]string
7877 InstanceTagError bool
7978}
8079
81- func mockMetadataProviderFunc () ec2metadataprovider.MetadataProvider {
80+ var _ ec2metadataprovider.MetadataProvider = (* mockMetadataProvider )(nil )
81+
82+ func mockMetadataProviderFunc (context.Context ) ec2metadataprovider.MetadataProvider {
8283 return & mockMetadataProvider {
8384 Tags : map [string ]string {
8485 "aws:autoscaling:groupName" : "ASG-1" ,
8586 },
86- InstanceIdentityDocument : & ec2metadata. EC2InstanceIdentityDocument {
87+ InstanceIdentityDocument : & imds. InstanceIdentityDocument {
8788 InstanceID : "i-123456789" ,
8889 },
8990 }
9091}
9192
9293func mockMetadataProviderWithAccountId (accountId string ) * mockMetadataProvider {
9394 return & mockMetadataProvider {
94- InstanceIdentityDocument : & ec2metadata. EC2InstanceIdentityDocument {
95+ InstanceIdentityDocument : & imds. InstanceIdentityDocument {
9596 AccountID : accountId ,
9697 },
9798 }
9899}
99100
100- func (m * mockMetadataProvider ) Get (ctx context.Context ) (ec2metadata. EC2InstanceIdentityDocument , error ) {
101+ func (m * mockMetadataProvider ) Get (context.Context ) (imds. InstanceIdentityDocument , error ) {
101102 if m .InstanceIdentityDocument != nil {
102103 return * m .InstanceIdentityDocument , nil
103104 }
104- return ec2metadata. EC2InstanceIdentityDocument {}, errors .New ("No instance identity document" )
105+ return imds. InstanceIdentityDocument {}, errors .New ("no instance identity document" )
105106}
106107
107- func (m * mockMetadataProvider ) Hostname (ctx context.Context ) (string , error ) {
108+ func (m * mockMetadataProvider ) Hostname (context.Context ) (string , error ) {
108109 return "MockHostName" , nil
109110}
110111
111- func (m * mockMetadataProvider ) InstanceID (ctx context.Context ) (string , error ) {
112+ func (m * mockMetadataProvider ) InstanceID (context.Context ) (string , error ) {
112113 return "MockInstanceID" , nil
113114}
114115
115- func (m * mockMetadataProvider ) InstanceTags (_ context.Context ) ([]string , error ) {
116+ func (m * mockMetadataProvider ) InstanceTags (context.Context ) ([]string , error ) {
116117 if m .InstanceTagError {
117118 return nil , errors .New ("an error occurred for instance tag retrieval" )
118119 }
119120 return maps .Keys (m .Tags ), nil
120121}
121122
122- func (m * mockMetadataProvider ) ClientIAMRole (ctx context.Context ) (string , error ) {
123+ func (m * mockMetadataProvider ) ClientIAMRole (context.Context ) (string , error ) {
123124 return "TestRole" , nil
124125}
125126
126- func (m * mockMetadataProvider ) InstanceTagValue (ctx context.Context , tagKey string ) (string , error ) {
127+ func (m * mockMetadataProvider ) InstanceTagValue (_ context.Context , tagKey string ) (string , error ) {
127128 tag , ok := m .Tags [tagKey ]
128129 if ! ok {
129130 return "" , errors .New ("tag not found" )
@@ -333,10 +334,9 @@ func TestEntityStore_createLogFileRID(t *testing.T) {
333334 sp .On ("logFileServiceAttribute" , glob , group ).Return (serviceAttr )
334335 sp .On ("getAutoScalingGroup" ).Return ("ASG-1" )
335336 e := EntityStore {
336- mode : config .ModeEC2 ,
337- ec2Info : EC2Info {InstanceID : instanceId , AccountID : accountId },
338- serviceprovider : sp ,
339- nativeCredential : & session.Session {},
337+ mode : config .ModeEC2 ,
338+ ec2Info : EC2Info {InstanceID : instanceId , AccountID : accountId },
339+ serviceprovider : sp ,
340340 }
341341
342342 entity := e .CreateLogFileEntity (glob , group )
@@ -364,9 +364,8 @@ func TestEntityStore_createLogFileRID_ServiceProviderIsEmpty(t *testing.T) {
364364 glob := LogFileGlob ("glob" )
365365 group := LogGroupName ("group" )
366366 e := EntityStore {
367- mode : config .ModeEC2 ,
368- ec2Info : EC2Info {InstanceID : instanceId },
369- nativeCredential : & session.Session {},
367+ mode : config .ModeEC2 ,
368+ ec2Info : EC2Info {InstanceID : instanceId },
370369 }
371370
372371 entity := e .CreateLogFileEntity (glob , group )
@@ -548,7 +547,6 @@ func TestEntityStore_GetMetricServiceNameSource(t *testing.T) {
548547 ec2Info : EC2Info {InstanceID : instanceId },
549548 serviceprovider : sp ,
550549 metadataprovider : mockMetadataProviderWithAccountId (accountId ),
551- nativeCredential : & session.Session {},
552550 }
553551
554552 serviceName , serviceNameSource := e .GetMetricServiceNameAndSource ()
@@ -564,7 +562,6 @@ func TestEntityStore_GetMetricServiceNameSource_ServiceProviderEmpty(t *testing.
564562 mode : config .ModeEC2 ,
565563 ec2Info : EC2Info {InstanceID : instanceId },
566564 metadataprovider : mockMetadataProviderWithAccountId (accountId ),
567- nativeCredential : & session.Session {},
568565 }
569566
570567 serviceName , serviceNameSource := e .GetMetricServiceNameAndSource ()
0 commit comments