@@ -207,7 +207,116 @@ describe('Connect Tests', function () {
207
207
} ) ;
208
208
} ) ;
209
209
210
- context ( 'prepareHandshakeDocument' , ( ) => {
210
+ describe ( 'prepareHandshakeDocument' , ( ) => {
211
+ describe ( 'client environment (containers and FAAS)' , ( ) => {
212
+ const cachedEnv = process . env ;
213
+
214
+ context ( 'when only kubernetes is present' , ( ) => {
215
+ const authContext = {
216
+ connection : { } ,
217
+ options : { ...CONNECT_DEFAULTS }
218
+ } ;
219
+
220
+ beforeEach ( ( ) => {
221
+ process . env . KUBERNETES_SERVICE_HOST = 'I exist' ;
222
+ } ) ;
223
+
224
+ afterEach ( ( ) => {
225
+ if ( cachedEnv . KUBERNETES_SERVICE_HOST != null ) {
226
+ process . env . KUBERNETES_SERVICE_HOST = cachedEnv . KUBERNETES_SERVICE_HOST ;
227
+ } else {
228
+ delete process . env . KUBERNETES_SERVICE_HOST ;
229
+ }
230
+ } ) ;
231
+
232
+ it ( `should include { orchestrator: 'kubernetes'} in client.env.container` , async ( ) => {
233
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
234
+ expect ( handshakeDocument . client . env . container . orchestrator ) . to . equal ( 'kubernetes' ) ;
235
+ } ) ;
236
+
237
+ it ( `should not have 'name' property in client.env ` , async ( ) => {
238
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
239
+ expect ( handshakeDocument . client . env ) . to . not . have . property ( 'name' ) ;
240
+ } ) ;
241
+ } ) ;
242
+
243
+ context ( 'when kubernetes and FAAS are both present' , ( ) => {
244
+ const authContext = {
245
+ connection : { } ,
246
+ options : { ...CONNECT_DEFAULTS , metadata : { env : { name : 'aws.lambda' } } }
247
+ } ;
248
+
249
+ beforeEach ( ( ) => {
250
+ process . env . KUBERNETES_SERVICE_HOST = 'I exist' ;
251
+ } ) ;
252
+
253
+ afterEach ( ( ) => {
254
+ if ( cachedEnv . KUBERNETES_SERVICE_HOST != null ) {
255
+ process . env . KUBERNETES_SERVICE_HOST = cachedEnv . KUBERNETES_SERVICE_HOST ;
256
+ } else {
257
+ delete process . env . KUBERNETES_SERVICE_HOST ;
258
+ }
259
+ } ) ;
260
+
261
+ it ( `should include { orchestrator: 'kubernetes'} in client.env.container` , async ( ) => {
262
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
263
+ expect ( handshakeDocument . client . env . container . orchestrator ) . to . equal ( 'kubernetes' ) ;
264
+ } ) ;
265
+
266
+ it ( `should still have properly set 'name' property in client.env ` , async ( ) => {
267
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
268
+ expect ( handshakeDocument . client . env . name ) . to . equal ( 'aws.lambda' ) ;
269
+ } ) ;
270
+ } ) ;
271
+
272
+ context ( 'when container nor FAAS env is not present (empty string case)' , ( ) => {
273
+ const authContext = {
274
+ connection : { } ,
275
+ options : { ...CONNECT_DEFAULTS }
276
+ } ;
277
+
278
+ context ( 'when process.env.KUBERNETES_SERVICE_HOST = undefined' , ( ) => {
279
+ beforeEach ( ( ) => {
280
+ delete process . env . KUBERNETES_SERVICE_HOST ;
281
+ } ) ;
282
+
283
+ afterEach ( ( ) => {
284
+ afterEach ( ( ) => {
285
+ if ( cachedEnv . KUBERNETES_SERVICE_HOST != null ) {
286
+ process . env . KUBERNETES_SERVICE_HOST = cachedEnv . KUBERNETES_SERVICE_HOST ;
287
+ } else {
288
+ delete process . env . KUBERNETES_SERVICE_HOST ;
289
+ }
290
+ } ) ;
291
+ } ) ;
292
+
293
+ it ( `should not have 'env' property in client` , async ( ) => {
294
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
295
+ expect ( handshakeDocument . client ) . to . not . have . property ( 'env' ) ;
296
+ } ) ;
297
+ } ) ;
298
+
299
+ context ( 'when process.env.KUBERNETES_SERVICE_HOST is an empty string' , ( ) => {
300
+ beforeEach ( ( ) => {
301
+ process . env . KUBERNETES_SERVICE_HOST = '' ;
302
+ } ) ;
303
+
304
+ afterEach ( ( ) => {
305
+ if ( cachedEnv . KUBERNETES_SERVICE_HOST != null ) {
306
+ process . env . KUBERNETES_SERVICE_HOST = cachedEnv . KUBERNETES_SERVICE_HOST ;
307
+ } else {
308
+ delete process . env . KUBERNETES_SERVICE_HOST ;
309
+ }
310
+ } ) ;
311
+
312
+ it ( `should not have 'env' property in client` , async ( ) => {
313
+ const handshakeDocument = await prepareHandshakeDocument ( authContext ) ;
314
+ expect ( handshakeDocument . client ) . to . not . have . property ( 'env' ) ;
315
+ } ) ;
316
+ } ) ;
317
+ } ) ;
318
+ } ) ;
319
+
211
320
context ( 'when serverApi.version is present' , ( ) => {
212
321
const options = {
213
322
authProviders : new MongoClientAuthProviders ( )
0 commit comments