Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Mancioppi committed May 6, 2023
1 parent 46fa4cf commit c922bc6
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMaxSize, safeRequire } from './utils';
import { getSpanAttributeMaxLength, safeRequire } from './utils';

describe('utils tests', () => {
afterEach(() => {
Expand Down Expand Up @@ -30,40 +30,42 @@ describe('utils tests', () => {
});
});

describe('get max size value according to env. vars', () => {
beforeEach(() => {
jest.resetModules();
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = undefined;
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = undefined;
});
describe('getSpanAttributeMaxLength', () => {
describe('value according to env. vars', () => {
beforeEach(() => {
jest.resetModules();
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = undefined;
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = undefined;
});

it('get max size when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT is set', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = '1';
const size = getMaxSize();
expect(size).toEqual(1);
});
it('when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT is set', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = '1';
const size = getSpanAttributeMaxLength();
expect(size).toEqual(1);
});

it('get max size when OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT is set', () => {
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '50';
const size = getMaxSize();
expect(size).toEqual(50);
});
it('when OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT is set', () => {
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '50';
const size = getSpanAttributeMaxLength();
expect(size).toEqual(50);
});

it('get max size when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT and OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT are set', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = '1';
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '50';
const size = getMaxSize();
expect(size).toEqual(1);
});
it('when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT and OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT are set', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = '1';
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = '50';
const size = getSpanAttributeMaxLength();
expect(size).toEqual(1);
});

it('get max size when no env. vars are set, get default value', () => {
const size = getMaxSize();
expect(size).toEqual(2048);
});
it('when no env. vars are set, get default value', () => {
const size = getSpanAttributeMaxLength();
expect(size).toEqual(2048);
});

it('get max size when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT is set to NaN will return default value', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = 'a';
const size = getMaxSize();
expect(size).toEqual(2048);
it('when OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT is set to NaN will return default value', () => {
process.env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = 'a';
const size = getSpanAttributeMaxLength();
expect(size).toEqual(2048);
});
});
});

0 comments on commit c922bc6

Please sign in to comment.