@@ -37,28 +37,63 @@ describe('client metadata module', () => {
37
37
} ) ;
38
38
39
39
describe ( 'getFAASEnv()' , function ( ) {
40
- const tests : Array < [ string , string ] > = [
41
- [ 'AWS_EXECUTION_ENV' , 'aws.lambda' ] ,
40
+ const tests : Array < [ envVariable : string , provider : string ] > = [
42
41
[ 'AWS_LAMBDA_RUNTIME_API' , 'aws.lambda' ] ,
43
42
[ 'FUNCTIONS_WORKER_RUNTIME' , 'azure.func' ] ,
44
43
[ 'K_SERVICE' , 'gcp.func' ] ,
45
44
[ 'FUNCTION_NAME' , 'gcp.func' ] ,
46
45
[ 'VERCEL' , 'vercel' ]
47
46
] ;
48
47
for ( const [ envVariable , provider ] of tests ) {
49
- context ( `when ${ envVariable } is in the environment ` , ( ) => {
48
+ context ( `when ${ envVariable } is set to a non-empty string ` , ( ) => {
50
49
before ( ( ) => {
51
- process . env [ envVariable ] = 'non empty string ' ;
50
+ process . env [ envVariable ] = 'non_empty_string ' ;
52
51
} ) ;
53
52
after ( ( ) => {
54
53
delete process . env [ envVariable ] ;
55
54
} ) ;
56
55
it ( 'determines the correct provider' , ( ) => {
57
56
expect ( getFAASEnv ( ) ?. get ( 'name' ) ) . to . equal ( provider ) ;
58
57
} ) ;
58
+
59
+ context ( `when ${ envVariable } is set to an empty string` , ( ) => {
60
+ before ( ( ) => {
61
+ process . env [ envVariable ] = '' ;
62
+ } ) ;
63
+ after ( ( ) => {
64
+ delete process . env [ envVariable ] ;
65
+ } ) ;
66
+ it ( 'returns null' , ( ) => {
67
+ expect ( getFAASEnv ( ) ) . to . be . null ;
68
+ } ) ;
69
+ } ) ;
59
70
} ) ;
60
71
}
61
72
73
+ context ( 'when AWS_EXECUTION_ENV starts with "AWS_Lambda_"' , ( ) => {
74
+ before ( ( ) => {
75
+ process . env . AWS_EXECUTION_ENV = 'AWS_Lambda_correctStartString' ;
76
+ } ) ;
77
+ after ( ( ) => {
78
+ delete process . env . AWS_EXECUTION_ENV ;
79
+ } ) ;
80
+ it ( 'indicates the runtime is aws lambda' , ( ) => {
81
+ expect ( getFAASEnv ( ) ?. get ( 'name' ) ) . to . equal ( 'aws.lambda' ) ;
82
+ } ) ;
83
+ } ) ;
84
+
85
+ context ( 'when AWS_EXECUTION_ENV does not start with "AWS_Lambda_"' , ( ) => {
86
+ before ( ( ) => {
87
+ process . env . AWS_EXECUTION_ENV = 'AWS_LambdaIncorrectStartString' ;
88
+ } ) ;
89
+ after ( ( ) => {
90
+ delete process . env . AWS_EXECUTION_ENV ;
91
+ } ) ;
92
+ it ( 'returns null' , ( ) => {
93
+ expect ( getFAASEnv ( ) ) . to . be . null ;
94
+ } ) ;
95
+ } ) ;
96
+
62
97
context ( 'when there is no FAAS provider data in the env' , ( ) => {
63
98
it ( 'returns null' , ( ) => {
64
99
expect ( getFAASEnv ( ) ) . to . be . null ;
@@ -69,9 +104,9 @@ describe('client metadata module', () => {
69
104
context ( 'unrelated environments' , ( ) => {
70
105
before ( ( ) => {
71
106
// aws
72
- process . env . AWS_EXECUTION_ENV = 'non-empty-string ' ;
107
+ process . env . AWS_EXECUTION_ENV = 'AWS_Lambda_non_empty_string ' ;
73
108
// azure
74
- process . env . FUNCTIONS_WORKER_RUNTIME = 'non-empty-string ' ;
109
+ process . env . FUNCTIONS_WORKER_RUNTIME = 'non_empty_string ' ;
75
110
} ) ;
76
111
after ( ( ) => {
77
112
delete process . env . AWS_EXECUTION_ENV ;
@@ -85,10 +120,10 @@ describe('client metadata module', () => {
85
120
context ( 'vercel and aws which share env variables' , ( ) => {
86
121
before ( ( ) => {
87
122
// vercel
88
- process . env . VERCEL = 'non-empty-string ' ;
123
+ process . env . VERCEL = 'non_empty_string ' ;
89
124
// aws
90
- process . env . AWS_EXECUTION_ENV = 'non-empty-string ' ;
91
- process . env . AWS_LAMBDA_RUNTIME_API = 'non-empty-string ' ;
125
+ process . env . AWS_EXECUTION_ENV = 'non_empty_string ' ;
126
+ process . env . AWS_LAMBDA_RUNTIME_API = 'non_empty_string ' ;
92
127
} ) ;
93
128
after ( ( ) => {
94
129
delete process . env . VERCEL ;
@@ -383,15 +418,15 @@ describe('client metadata module', () => {
383
418
aws : [
384
419
{
385
420
context : 'no additional metadata' ,
386
- env : [ [ 'AWS_EXECUTION_ENV' , 'non-empty string ' ] ] ,
421
+ env : [ [ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_non_empty_string ' ] ] ,
387
422
outcome : {
388
423
name : 'aws.lambda'
389
424
}
390
425
} ,
391
426
{
392
427
context : 'AWS_REGION provided' ,
393
428
env : [
394
- [ 'AWS_EXECUTION_ENV' , 'non-empty string ' ] ,
429
+ [ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_non_empty_string ' ] ,
395
430
[ 'AWS_REGION' , 'non-null' ]
396
431
] ,
397
432
outcome : {
@@ -402,7 +437,7 @@ describe('client metadata module', () => {
402
437
{
403
438
context : 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE provided' ,
404
439
env : [
405
- [ 'AWS_EXECUTION_ENV' , 'non-empty string ' ] ,
440
+ [ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_non_empty_string ' ] ,
406
441
[ 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , '3' ]
407
442
] ,
408
443
outcome : {
@@ -506,7 +541,7 @@ describe('client metadata module', () => {
506
541
507
542
context ( 'when a numeric FAAS env variable is not numerically parsable' , ( ) => {
508
543
before ( ( ) => {
509
- process . env . AWS_EXECUTION_ENV = 'non-empty-string ' ;
544
+ process . env . AWS_EXECUTION_ENV = 'AWS_Lambda_non_empty_string ' ;
510
545
process . env . AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '123not numeric' ;
511
546
} ) ;
512
547
@@ -525,7 +560,7 @@ describe('client metadata module', () => {
525
560
context ( 'when faas region is too large' , ( ) => {
526
561
beforeEach ( '1. Omit fields from `env` except `env.name`.' , ( ) => {
527
562
sinon . stub ( process , 'env' ) . get ( ( ) => ( {
528
- AWS_EXECUTION_ENV : 'iLoveJavaScript ' ,
563
+ AWS_EXECUTION_ENV : 'AWS_Lambda_iLoveJavaScript ' ,
529
564
AWS_REGION : 'a' . repeat ( 512 )
530
565
} ) ) ;
531
566
} ) ;
@@ -542,7 +577,7 @@ describe('client metadata module', () => {
542
577
context ( 'release too large' , ( ) => {
543
578
beforeEach ( '2. Omit fields from `os` except `os.type`.' , ( ) => {
544
579
sinon . stub ( process , 'env' ) . get ( ( ) => ( {
545
- AWS_EXECUTION_ENV : 'iLoveJavaScript ' ,
580
+ AWS_EXECUTION_ENV : 'AWS_Lambda_iLoveJavaScript ' ,
546
581
AWS_REGION : 'abc'
547
582
} ) ) ;
548
583
sinon . stub ( os , 'release' ) . returns ( 'a' . repeat ( 512 ) ) ;
0 commit comments