Skip to content

Commit 88ae5f1

Browse files
committed
chore: updated unit test case
1 parent b553fea commit 88ae5f1

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

Diff for: layer-publisher/tests/unit/__snapshots__/layer-publisher.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Object {
3232
"S3Bucket": Object {
3333
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}",
3434
},
35-
"S3Key": "c2f621503b147cecccf2e6cc6df420a8f11ee29ae042d2c1f523cf5db3f47ca2.zip",
35+
"S3Key": "dbdb3f66eaeed03649521bf73dbcdd95a713086afccbac3f57fa407ffb76bdaa.zip",
3636
},
3737
"Description": "Lambda Powertools for TypeScript version 1.0.1",
3838
"LayerName": "AWSLambdaPowertoolsTypeScript",

Diff for: packages/commons/src/config/EnvironmentVariablesService.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ class EnvironmentVariablesService extends ConfigService {
5252
*
5353
* @returns {string}
5454
*/
55-
public getXrayTraceId(): string {
55+
public getXrayTraceId(): string | undefined {
5656
const xRayTraceId = this.get(this.xRayTraceIdVariable);
5757

58+
if (xRayTraceId === '') return undefined;
59+
5860
return xRayTraceId.split(';')[0].replace('Root=', '');
5961
}
6062

Diff for: packages/commons/tests/unit/config/EnvironmentVariablesService.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ describe('Class: EnvironmentVariablesService', () => {
8282
// Assess
8383
expect(value).toEqual('abcd123456789');
8484
});
85+
test('It returns the value of the Root X-Ray segment ID properly formatted', () => {
86+
87+
// Prepare
88+
process.env._X_AMZN_TRACE_ID = 'Root=1-5759e988-bd862e3fe1be46a994272793;Parent=557abcec3ee5a047;Sampled=1';
89+
const service = new EnvironmentVariablesService();
90+
91+
// Act
92+
const value = service.getXrayTraceId();
93+
94+
// Assess
95+
expect(value).toEqual('1-5759e988-bd862e3fe1be46a994272793');
96+
});
97+
98+
test('It returns the value of the Root X-Ray segment ID properly formatted', () => {
99+
100+
// Prepare
101+
delete process.env._X_AMZN_TRACE_ID;
102+
const service = new EnvironmentVariablesService();
103+
104+
// Act
105+
const value = service.getXrayTraceId();
106+
107+
// Assess
108+
expect(value).toEqual(undefined);
109+
});
85110

86111
});
87112

Diff for: packages/tracer/src/Tracer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class Tracer extends Utility implements TracerInterface {
497497
*
498498
* @returns string - The root X-Ray trace id.
499499
*/
500-
public getRootXrayTraceId(): string {
500+
public getRootXrayTraceId(): string | undefined {
501501
return this.envVarsService.getXrayTraceId();
502502
}
503503

Diff for: packages/tracer/src/TracerInterface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface TracerInterface {
1212
captureLambdaHandler(options?: CaptureLambdaHandlerOptions): HandlerMethodDecorator
1313
captureMethod(options?: CaptureMethodOptions): MethodDecorator
1414
getSegment(): Segment | Subsegment
15-
getRootXrayTraceId(): string
15+
getRootXrayTraceId(): string | undefined
1616
isTracingEnabled(): boolean
1717
putAnnotation: (key: string, value: string | number | boolean) => void
1818
putMetadata: (key: string, value: unknown, namespace?: string | undefined) => void

0 commit comments

Comments
 (0)