Skip to content

Commit 3c0f129

Browse files
committed
updated unit tests
1 parent c08a34a commit 3c0f129

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/test/exporter/otlp/aws/logs/aws-cw-otlp-batch-log-record-processor.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ describe('AwsCloudWatchOtlpBatchLogRecordProcessor', () => {
2121
const nestedDictLog = generateTestLogData(logBody, logKey, logDepth, 1, true)[0];
2222
const nestedArrayLog = generateTestLogData(logBody, logKey, logDepth, 1, false)[0];
2323

24-
const expectedDictSize = logKey.length * logDepth + logBody.length;
25-
const expectedArraySize = logBody.length;
24+
const expectedDictSize = logKey.length * logDepth + logBody.length + BASE_LOG_BUFFER_BYTE_SIZE;
25+
const expectedArraySize = logBody.length + BASE_LOG_BUFFER_BYTE_SIZE;
2626

2727
const dictSize = (AwsCloudWatchOtlpBatchLogRecordProcessor as any).estimateLogSize(nestedDictLog, logDepth);
2828
const arraySize = (AwsCloudWatchOtlpBatchLogRecordProcessor as any).estimateLogSize(nestedArrayLog, logDepth);
2929

30-
expect(dictSize - BASE_LOG_BUFFER_BYTE_SIZE).toBe(expectedDictSize);
31-
expect(arraySize - BASE_LOG_BUFFER_BYTE_SIZE).toBe(expectedArraySize);
30+
expect(dictSize).toBe(expectedDictSize);
31+
expect(arraySize).toBe(expectedArraySize);
3232
});
3333

3434
it('should handle both body and attributes', () => {
@@ -44,26 +44,29 @@ describe('AwsCloudWatchOtlpBatchLogRecordProcessor', () => {
4444
attributes: { [attrKey]: attrValue },
4545
};
4646

47-
const expectedSize = logBody.length + attrKey.length + attrValue.length;
47+
const expectedSize = logBody.length + attrKey.length + attrValue.length + BASE_LOG_BUFFER_BYTE_SIZE;
4848
const actualSize = (AwsCloudWatchOtlpBatchLogRecordProcessor as any).estimateLogSize(record);
4949

50-
expect(actualSize - BASE_LOG_BUFFER_BYTE_SIZE).toBe(expectedSize);
50+
expect(actualSize).toBe(expectedSize);
5151
});
5252

5353
it('should cut off calculation for nested structure that exceeds depth limit', () => {
5454
const maxDepth = 0;
5555
const calculatedBody = 'X'.repeat(400);
5656
const logBody = {
5757
calculated: 'X'.repeat(400),
58-
restOfThisLogWillBeTruncated: {
58+
thisDataWillNotBeIncludedInSizeCalculation: {
5959
truncated: {
6060
test: 'X'.repeat(MAX_LOG_REQUEST_BYTE_SIZE),
6161
},
6262
},
6363
};
6464

6565
const expectedSize =
66-
BASE_LOG_BUFFER_BYTE_SIZE + 'calculated'.length + calculatedBody.length + 'restOfThisLogWillBeTruncated'.length;
66+
BASE_LOG_BUFFER_BYTE_SIZE +
67+
'calculated'.length +
68+
calculatedBody.length +
69+
'thisDataWillNotBeIncludedInSizeCalculation'.length;
6770

6871
const testLogs = generateTestLogData(logBody, 'key', 0, 1, true);
6972
const dictSize = (AwsCloudWatchOtlpBatchLogRecordProcessor as any).estimateLogSize(testLogs[0], maxDepth);

0 commit comments

Comments
 (0)