Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit a128f42

Browse files
author
Amir Blum
committed
test(opentelemetry-plugin-aws-sdk): add few tests to suite
1 parent ee3e3d6 commit a128f42

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

packages/plugin-aws-sdk/test/aws-sdk.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ describe("plugin-aws-sdk", () => {
217217
);
218218
done();
219219
});
220+
221+
it("should create span if no callback is supplied", (done) => {
222+
const s3 = new AWS.S3();
223+
const bucketName = "aws-test-bucket";
224+
225+
s3.putObject({
226+
Bucket: bucketName,
227+
Key: "key name from tests",
228+
Body: "Hello World!",
229+
}).send();
230+
231+
setImmediate(() => {
232+
const awsSpans = getAwsSpans();
233+
expect(awsSpans.length).toBe(1);
234+
done();
235+
});
236+
});
220237
});
221238

222239
describe("send return error", () => {

packages/plugin-aws-sdk/test/sqs.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ describe("sqs", () => {
7373
};
7474

7575
it("should set parent context in sqs receive callback", async (done) => {
76+
const sqs = new AWS.SQS();
77+
sqs.receiveMessage(
78+
{
79+
QueueUrl: "queue/url/for/unittests",
80+
},
81+
(err: AWSError, data: AWS.SQS.Types.ReceiveMessageResult) => {
82+
expect(err).toBeFalsy();
83+
createReceiveChildSpan();
84+
expectReceiverWithChildSpan(memoryExporter.getFinishedSpans());
85+
done();
86+
}
87+
);
88+
});
89+
90+
it("should set parent context in sqs receive 'send' callback", async (done) => {
7691
const sqs = new AWS.SQS();
7792
sqs
7893
.receiveMessage({

packages/plugin-aws-sdk/test/testing-utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import AWS from "aws-sdk";
22

33
export const mockAwsSend = (sendResult: any, data: any = undefined) => {
4-
AWS.Request.prototype.send = function (cb: (error, response) => void) {
5-
(this as AWS.Request<any, any>).on("complete", (response) => {
6-
cb(response.error, response);
7-
});
4+
AWS.Request.prototype.send = function (cb?: (error, response) => void) {
5+
if (cb) {
6+
(this as AWS.Request<any, any>).on("complete", (response) => {
7+
cb(response.error, response);
8+
});
9+
}
810
const response = {
911
...sendResult,
1012
data,

0 commit comments

Comments
 (0)