@@ -8,14 +8,31 @@ import {
8
8
LEGACY_HELLO_COMMAND ,
9
9
type MongoClient
10
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
+
11
29
describe ( 'Handshake Prose Tests' , function ( ) {
12
30
let client : MongoClient ;
13
31
14
32
afterEach ( async function ( ) {
15
33
await client ?. close ( ) ;
16
34
} ) ;
17
35
18
- type EnvironmentVariables = Array < [ string , string ] > ;
19
36
const tests : Array < {
20
37
context : string ;
21
38
expectedProvider : string | undefined ;
@@ -86,16 +103,7 @@ describe('Handshake Prose Tests', function () {
86
103
87
104
for ( const { context : name , env, expectedProvider } of tests ) {
88
105
context ( name , function ( ) {
89
- before ( ( ) => {
90
- for ( const [ key , value ] of env ) {
91
- process . env [ key ] = value ;
92
- }
93
- } ) ;
94
- after ( ( ) => {
95
- for ( const [ key ] of env ) {
96
- delete process . env [ key ] ;
97
- }
98
- } ) ;
106
+ stubEnv ( env ) ;
99
107
100
108
it ( `metadata confirmation test for ${ name } ` , function ( ) {
101
109
expect ( getFAASEnv ( ) ?. get ( 'name' ) ) . to . equal (
@@ -117,22 +125,12 @@ describe('Handshake Prose Tests', function () {
117
125
}
118
126
119
127
context ( 'Test 9: Valid container and FaaS provider' , function ( ) {
120
- const env = [
128
+ stubEnv ( [
121
129
[ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_java8' ] ,
122
130
[ 'AWS_REGION' , 'us-east-2' ] ,
123
131
[ 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , '1024' ] ,
124
132
[ 'KUBERNETES_SERVICE_HOST' , '1' ]
125
- ] as EnvironmentVariables ;
126
- before ( ( ) => {
127
- for ( const [ key , value ] of env ) {
128
- process . env [ key ] = value ;
129
- }
130
- } ) ;
131
- after ( ( ) => {
132
- for ( const [ key ] of env ) {
133
- delete process . env [ key ] ;
134
- }
135
- } ) ;
133
+ ] ) ;
136
134
137
135
it ( 'runs a hello successfully' , async function ( ) {
138
136
client = this . configuration . newClient ( {
0 commit comments