Skip to content

Commit e45f653

Browse files
committed
Update unit test
1 parent f4ece31 commit e45f653

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

internal/metadataproviders/aws/ec2/metadata_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ func TestGetMetadataFromImds(t *testing.T) {
9898
expect: []byte("this is the body foo bar baz"),
9999
wantErr: false,
100100
},
101+
{
102+
name: "Successfully retrieves Instance Life Cycle metadata",
103+
client: func(t *testing.T) ImdsGetMetadataAPI {
104+
return mockGetMetadataAPI(func(_ context.Context, params *imds.GetMetadataInput, _ ...func(*imds.Options)) (*imds.GetMetadataOutput, error) {
105+
t.Helper()
106+
if e, a := "instance-life-cycle", params.Path; e != a {
107+
t.Errorf("expected Path: %v, got: %v", e, a)
108+
}
109+
return &imds.GetMetadataOutput{
110+
Content: io.NopCloser(bytes.NewReader([]byte("this is the body foo bar baz"))),
111+
}, nil
112+
})
113+
},
114+
path: "instance-life-cycle",
115+
expect: []byte("this is the body foo bar baz"),
116+
wantErr: false,
117+
},
101118
{
102119
name: "Path is empty",
103120
client: func(t *testing.T) ImdsGetMetadataAPI {

processor/resourcedetectionprocessor/internal/aws/ec2/ec2_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ func (mm mockMetadata) InstanceID(_ context.Context) (string, error) {
5757
return "", nil
5858
}
5959

60+
func (mm mockMetadata) InstanceLifeCycle(_ context.Context) (string, error) {
61+
if !mm.isAvailable {
62+
return "", errUnavailable
63+
}
64+
return "on-demand", nil
65+
}
66+
6067
func (mm mockMetadata) Get(_ context.Context) (imds.InstanceIdentityDocument, error) {
6168
if mm.retErrIDDoc != nil {
6269
return imds.InstanceIdentityDocument{}, mm.retErrIDDoc
@@ -180,6 +187,7 @@ func TestDetector_Detect(t *testing.T) {
180187
want: func() pcommon.Resource {
181188
res := pcommon.NewResource()
182189
attr := res.Attributes()
190+
attr.PutStr("aws.ec2.instance_life_cycle", "on-demand")
183191
attr.PutStr("cloud.account.id", "account1234")
184192
attr.PutStr("cloud.provider", "aws")
185193
attr.PutStr("cloud.platform", "aws_ec2")
@@ -211,6 +219,7 @@ func TestDetector_Detect(t *testing.T) {
211219
want: func() pcommon.Resource {
212220
res := pcommon.NewResource()
213221
attr := res.Attributes()
222+
attr.PutStr("aws.ec2.instance_life_cycle", "on-demand")
214223
attr.PutStr("cloud.account.id", "account1234")
215224
attr.PutStr("cloud.provider", "aws")
216225
attr.PutStr("cloud.platform", "aws_ec2")
@@ -244,6 +253,7 @@ func TestDetector_Detect(t *testing.T) {
244253
want: func() pcommon.Resource {
245254
res := pcommon.NewResource()
246255
attr := res.Attributes()
256+
attr.PutStr("aws.ec2.instance_life_cycle", "on-demand")
247257
attr.PutStr("cloud.account.id", "account1234")
248258
attr.PutStr("cloud.provider", "aws")
249259
attr.PutStr("cloud.platform", "aws_ec2")

0 commit comments

Comments
 (0)