1
1
import { expect } from 'chai' ;
2
2
import * as sinon from 'sinon' ;
3
3
4
- import { Connection , getFAASEnv , LEGACY_HELLO_COMMAND , type MongoClient } from '../../mongodb' ;
4
+ import {
5
+ Connection ,
6
+ getFAASEnv ,
7
+ Int32 ,
8
+ LEGACY_HELLO_COMMAND ,
9
+ type MongoClient
10
+ } from '../../mongodb' ;
11
+
12
+ type EnvironmentVariables = Array < [ string , string ] > ;
13
+
14
+ function stubEnv ( env : EnvironmentVariables ) {
15
+ let cachedEnv : NodeJS . ProcessEnv ;
16
+ before ( function ( ) {
17
+ cachedEnv = process . env ;
18
+ process . env = {
19
+ ...process . env ,
20
+ ...Object . fromEntries ( env )
21
+ } ;
22
+ } ) ;
23
+
24
+ after ( function ( ) {
25
+ process . env = cachedEnv ;
26
+ } ) ;
27
+ }
28
+
5
29
describe ( 'Handshake Prose Tests' , function ( ) {
6
30
let client : MongoClient ;
7
31
8
32
afterEach ( async function ( ) {
9
33
await client ?. close ( ) ;
10
34
} ) ;
11
35
12
- type EnvironmentVariables = Array < [ string , string ] > ;
13
36
const tests : Array < {
14
37
context : string ;
15
38
expectedProvider : string | undefined ;
@@ -80,16 +103,7 @@ describe('Handshake Prose Tests', function () {
80
103
81
104
for ( const { context : name , env, expectedProvider } of tests ) {
82
105
context ( name , function ( ) {
83
- before ( ( ) => {
84
- for ( const [ key , value ] of env ) {
85
- process . env [ key ] = value ;
86
- }
87
- } ) ;
88
- after ( ( ) => {
89
- for ( const [ key ] of env ) {
90
- delete process . env [ key ] ;
91
- }
92
- } ) ;
106
+ stubEnv ( env ) ;
93
107
94
108
it ( `metadata confirmation test for ${ name } ` , function ( ) {
95
109
expect ( getFAASEnv ( ) ?. get ( 'name' ) ) . to . equal (
@@ -110,6 +124,39 @@ describe('Handshake Prose Tests', function () {
110
124
} ) ;
111
125
}
112
126
127
+ context ( 'Test 9: Valid container and FaaS provider' , function ( ) {
128
+ stubEnv ( [
129
+ [ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_java8' ] ,
130
+ [ 'AWS_REGION' , 'us-east-2' ] ,
131
+ [ 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , '1024' ] ,
132
+ [ 'KUBERNETES_SERVICE_HOST' , '1' ]
133
+ ] ) ;
134
+
135
+ it ( 'runs a hello successfully' , async function ( ) {
136
+ client = this . configuration . newClient ( {
137
+ // if the handshake is not truncated, the `hello`s fail and the client does
138
+ // not connect. Lowering the server selection timeout causes the tests
139
+ // to fail more quickly in that scenario.
140
+ serverSelectionTimeoutMS : 3000
141
+ } ) ;
142
+ await client . connect ( ) ;
143
+ } ) ;
144
+
145
+ it ( 'includes both container and FAAS provider information in the client metadata' , async function ( ) {
146
+ client = this . configuration . newClient ( ) ;
147
+ await client . connect ( ) ;
148
+ expect ( client . topology ?. s . options . extendedMetadata ) . to . exist ;
149
+ const { env } = await client . topology . s . options . extendedMetadata ;
150
+
151
+ expect ( env ) . to . deep . equal ( {
152
+ region : 'us-east-2' ,
153
+ name : 'aws.lambda' ,
154
+ memory_mb : new Int32 ( 1024 ) ,
155
+ container : { orchestrator : 'kubernetes' }
156
+ } ) ;
157
+ } ) ;
158
+ } ) ;
159
+
113
160
context ( `Test 2: Test that the driver accepts an arbitrary auth mechanism` , function ( ) {
114
161
let stubCalled = false ;
115
162
beforeEach ( ( ) => {
0 commit comments