Skip to content

Commit 31aa39b

Browse files
committed
test(aws-sdk): use sinon to test propagation.inject calls
1 parent 6b4e532 commit 31aa39b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

plugins/node/opentelemetry-instrumentation-aws-sdk/test/MessageAttributes.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { propagation } from '@opentelemetry/api';
1718
import { expect } from 'expect';
19+
import * as sinon from 'sinon';
1820
import {
1921
MAX_MESSAGE_ATTRIBUTES,
2022
contextGetter,
@@ -71,6 +73,7 @@ describe('MessageAttributes', () => {
7173

7274
describe('injectPropagationContext', () => {
7375
it('should inject context if there are available attributes', () => {
76+
sinon.spy(propagation, "inject");
7477
const contextAttributes = {
7578
key1: { DataType: 'String', StringValue: 'value1' },
7679
key2: { DataType: 'String', StringValue: 'value2' },
@@ -79,12 +82,14 @@ describe('MessageAttributes', () => {
7982
key5: { DataType: 'String', StringValue: 'value5' },
8083
};
8184

82-
expect(Object.keys(contextAttributes).length).toBe(5);
8385
injectPropagationContext(contextAttributes);
84-
expect(Object.keys(contextAttributes).length).toBeGreaterThan(5);
86+
// @ts-expect-error Property 'calledOnce' does not exist on type
87+
expect(propagation.inject.calledOnce).toBe(true);
88+
sinon.restore();
8589
});
8690

8791
it('should not inject context if there not enough available attributes', () => {
92+
sinon.spy(propagation, "inject");
8893
const contextAttributes = {
8994
key1: { DataType: 'String', StringValue: 'value1' },
9095
key2: { DataType: 'String', StringValue: 'value2' },
@@ -98,9 +103,10 @@ describe('MessageAttributes', () => {
98103
key10: { DataType: 'String', StringValue: 'value10' },
99104
};
100105

101-
expect(Object.keys(contextAttributes).length).toBe(10);
102106
injectPropagationContext(contextAttributes);
103-
expect(Object.keys(contextAttributes).length).toBe(10);
107+
// @ts-expect-error Property 'calledOnce' does not exist on type
108+
expect(propagation.inject.calledOnce).toBe(false);
109+
sinon.restore();
104110
});
105111
});
106112

0 commit comments

Comments
 (0)