Skip to content

Commit

Permalink
test(instrumentation-fetch): use assert.deepStrictEqual where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
niekert committed Apr 8, 2021
1 parent 14e5103 commit 3207bf5
Showing 1 changed file with 19 additions and 38 deletions.
57 changes: 19 additions & 38 deletions packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const getData = (url: string, method?: string) =>
},
});

const CUSTOM_ATTRIBUTE_KEY = 'span kind';

const customAttributeFunction = (span: api.Span): void => {
span.setAttribute('span kind', api.SpanKind.CLIENT);
span.setAttribute(CUSTOM_ATTRIBUTE_KEY, api.SpanKind.CLIENT);
};

const defaultResource = {
Expand Down Expand Up @@ -336,49 +338,28 @@ describe('fetch', () => {
const keys = Object.keys(attributes);

assert.ok(
attributes[AttributeNames.COMPONENT] !== '',
`attributes ${AttributeNames.COMPONENT} is not defined`
);
assert.strictEqual(
attributes[HttpAttribute.HTTP_METHOD],
'GET',
`attributes ${HttpAttribute.HTTP_METHOD} is wrong`
);
assert.strictEqual(
attributes[HttpAttribute.HTTP_URL],
url,
`attributes ${HttpAttribute.HTTP_URL} is wrong`
);
assert.strictEqual(
attributes[HttpAttribute.HTTP_STATUS_CODE],
200,
`attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong`
);
assert.ok(
attributes[HttpAttribute.HTTP_STATUS_TEXT] === 'OK' ||
attributes[HttpAttribute.HTTP_STATUS_TEXT] === '',
`attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong`
attributes[HttpAttribute.HTTP_USER_AGENT] !== '',
`attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined`
);
assert.ok(
(attributes[HttpAttribute.HTTP_HOST] as string).indexOf('localhost') ===
0,
`attributes ${HttpAttribute.HTTP_HOST} is wrong`
);
assert.ok(
attributes[HttpAttribute.HTTP_SCHEME] === 'http' ||
attributes[HttpAttribute.HTTP_SCHEME] === 'https',
`attributes ${HttpAttribute.HTTP_SCHEME} is wrong`
);
assert.ok(
attributes[HttpAttribute.HTTP_USER_AGENT] !== '',
`attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined`
);
assert.ok(
(attributes[HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH] as number) > 0,
`attributes ${HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH} is <= 0`
);

assert.strictEqual(attributes['span kind'], api.SpanKind.CLIENT);
delete attributes[HttpAttribute.HTTP_USER_AGENT];
delete attributes[HttpAttribute.HTTP_HOST];

assert.deepStrictEqual(attributes, {
[AttributeNames.COMPONENT]: 'fetch',
[HttpAttribute.HTTP_METHOD]: 'GET',
[HttpAttribute.HTTP_URL]: url,
[HttpAttribute.HTTP_STATUS_CODE]: 200,
[HttpAttribute.HTTP_STATUS_TEXT]: 'OK',
[HttpAttribute.HTTP_SCHEME]: 'http',
[HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH]: 30,
[CUSTOM_ATTRIBUTE_KEY]: api.SpanKind.CLIENT,
});

assert.strictEqual(keys.length, 10, 'number of attributes is wrong');
});
Expand Down Expand Up @@ -635,7 +616,7 @@ describe('fetch', () => {
const attributes = span.attributes;

assert.strictEqual(
attributes['span kind'],
attributes[CUSTOM_ATTRIBUTE_KEY],
api.SpanKind.CLIENT,
'Custom attribute was not applied'
);
Expand Down

0 comments on commit 3207bf5

Please sign in to comment.