@@ -1054,8 +1054,7 @@ describe('Class: Tracer', () => {
1054
1054
1055
1055
// Prepare
1056
1056
const tracer : Tracer = new Tracer ( { enabled : false } ) ;
1057
- const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' )
1058
- . mockImplementation ( ( ) => null ) ;
1057
+ const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1059
1058
1060
1059
// Act
1061
1060
tracer . captureAWSClient ( { } ) ;
@@ -1065,20 +1064,62 @@ describe('Class: Tracer', () => {
1065
1064
1066
1065
} ) ;
1067
1066
1068
- test ( 'when called it returns the decorated object that was passed to it' , ( ) => {
1067
+ test ( 'when called with a simple AWS SDK v2 client, it returns it back instrumented ' , ( ) => {
1069
1068
1070
1069
// Prepare
1071
1070
const tracer : Tracer = new Tracer ( ) ;
1072
- const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' )
1073
- . mockImplementation ( ( ) => null ) ;
1071
+ const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1072
+ // Minimum shape required for a regular AWS v2 client (i.e. AWS.S3) to be instrumented
1073
+ const dummyClient = {
1074
+ customizeRequests : ( ) => null ,
1075
+ } ;
1074
1076
1075
1077
// Act
1076
- tracer . captureAWSClient ( { } ) ;
1078
+ tracer . captureAWSClient ( dummyClient ) ;
1077
1079
1078
1080
// Assess
1079
1081
expect ( captureAWSClientSpy ) . toBeCalledTimes ( 1 ) ;
1080
- expect ( captureAWSClientSpy ) . toBeCalledWith ( { } ) ;
1082
+ expect ( captureAWSClientSpy ) . toBeCalledWith ( dummyClient ) ;
1083
+
1084
+ } ) ;
1085
+
1086
+ test ( 'when called with a complex AWS SDK v2 client, it returns it back instrumented' , ( ) => {
1087
+
1088
+ // Prepare
1089
+ const tracer : Tracer = new Tracer ( ) ;
1090
+ const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1091
+ // Minimum shape required for a complex AWS v2 client (i.e. AWS.DocumentClient) to be instrumented
1092
+ const dummyClient = {
1093
+ service : {
1094
+ customizeRequests : ( ) => null ,
1095
+ }
1096
+ } ;
1097
+
1098
+ // Act
1099
+ tracer . captureAWSClient ( dummyClient ) ;
1100
+
1101
+ // Assess
1102
+ expect ( captureAWSClientSpy ) . toBeCalledTimes ( 2 ) ;
1103
+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 1 , dummyClient ) ;
1104
+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 2 , dummyClient . service ) ;
1105
+
1106
+ } ) ;
1107
+
1108
+ test ( 'when called with an uncompatible object, it throws an error' , ( ) => {
1081
1109
1110
+ // Prepare
1111
+ const tracer : Tracer = new Tracer ( ) ;
1112
+ const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1113
+
1114
+ // Act / Assess
1115
+ expect ( ( ) => {
1116
+ tracer . captureAWSClient ( { } ) ;
1117
+ } ) . toThrow ( 'service.customizeRequests is not a function' ) ;
1118
+ expect ( captureAWSClientSpy ) . toBeCalledTimes ( 2 ) ;
1119
+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 1 , { } ) ;
1120
+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 2 , undefined ) ;
1121
+ expect . assertions ( 4 ) ;
1122
+
1082
1123
} ) ;
1083
1124
1084
1125
} ) ;
0 commit comments