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