Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sns-publish-test-v3): add test for sns.publish for aws sdk v3 #1015

Merged
merged 7 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@aws-sdk/client-lambda": "3.37.0",
"@aws-sdk/client-s3": "3.37.0",
"@aws-sdk/client-sqs": "3.37.0",
"@aws-sdk/client-sns": "3.54.1",
"@aws-sdk/types": "3.37.0",
haddasbronfman marked this conversation as resolved.
Show resolved Hide resolved
"@opentelemetry/api": "1.0.1",
"@opentelemetry/contrib-test-utils": "0.29.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0"?><PublishResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/"><PublishResult><MessageId>90d1987b-4853-54ad-a499-c2d89c4edf3a</MessageId></PublishResult><ResponseMetadata><RequestId>d81e4f4f-2d70-51f3-a040-15ecf96d5a64</RequestId></ResponseMetadata></PublishResponse>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const instrumentation = registerInstrumentationTesting(
new AwsInstrumentation()
);
import * as AWS from 'aws-sdk';
import { SNS } from '@aws-sdk/client-sns';
haddasbronfman marked this conversation as resolved.
Show resolved Hide resolved
import * as fs from 'fs';
import * as nock from 'nock';

import { mockV2AwsSend } from './testing-utils';
import * as expect from 'expect';
Expand All @@ -41,7 +44,7 @@ const responseMockSuccess = {
const topicName = 'topic';
const fakeARN = `arn:aws:sns:region:000000000:${topicName}`;

describe('SNS', () => {
describe('SNS - v2', () => {
before(() => {
AWS.config.credentials = {
accessKeyId: 'test key id',
Expand All @@ -58,7 +61,7 @@ describe('SNS', () => {
} as AWS.SNS.Types.PublishResponse);
});

describe('publish', () => {
describe('publish - v2', () => {
haddasbronfman marked this conversation as resolved.
Show resolved Hide resolved
it('topic arn', async () => {
const sns = new AWS.SNS();

Expand Down Expand Up @@ -160,3 +163,70 @@ describe('SNS', () => {
});
});
});

describe('SNS - v3', () => {
let sns: any;
beforeEach(() => {
sns = new SNS({
region: 'us-east-1',
credentials: {
accessKeyId: 'abcde',
secretAccessKey: 'abcde',
},
});

nock('https://sns.us-east-1.amazonaws.com/')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sns-publish.xml', 'utf8')
);
});

describe('publish - v3', () => {
it('topic arn', async () => {
const topicV3Name = 'dummy-sns-v3-topic';
await sns.publish({
Message: 'sns message',
TopicArn: `arn:aws:sns:us-east-1:000000000:${topicV3Name}`,
});

const publishSpans = getTestSpans().filter(
(s: ReadableSpan) => s.name === `${topicV3Name} send`
);
expect(publishSpans.length).toBe(1);

const publishSpan = publishSpans[0];
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]
).toBe(MessagingDestinationKindValues.TOPIC);
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(topicV3Name);
expect(publishSpan.attributes[SemanticAttributes.RPC_METHOD]).toBe(
'Publish'
);
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toBe(
'aws.sns'
);
expect(publishSpan.kind).toBe(SpanKind.PRODUCER);
});

it('phone number', async () => {
const PhoneNumber = 'my phone number';
await sns.publish({
Message: 'sns message',
PhoneNumber,
});

const publishSpans = getTestSpans().filter(
(s: ReadableSpan) => s.name === 'phone_number send'
);
expect(publishSpans.length).toBe(1);
const publishSpan = publishSpans[0];
expect(
publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]
).toBe(PhoneNumber);
});
});
});