File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed
lib/mongo/server/app_metadata
mongo/server/app_metadata Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,6 @@ class ValueTooLong < Mongo::Error; end
78
78
} ,
79
79
80
80
'vercel' => {
81
- 'VERCEL_URL' => { field : :url , type : :string } ,
82
81
'VERCEL_REGION' => { field : :region , type : :string } ,
83
82
} ,
84
83
} . freeze
@@ -183,6 +182,11 @@ def detect_environment
183
182
matches = DISCRIMINATORS . keys . select { |k | discriminator_matches? ( k ) }
184
183
names = matches . map { |m | DISCRIMINATORS [ m ] [ :name ] } . uniq
185
184
185
+ # From the spec:
186
+ # When variables for multiple ``client.env.name`` values are present,
187
+ # ``vercel`` takes precedence over ``aws.lambda``; any other
188
+ # combination MUST cause ``client.env`` to be entirely omitted.
189
+ return 'vercel' if names . sort == %w[ aws.lambda vercel ]
186
190
raise TooManyEnvironments , names . join ( ', ' ) if names . length > 1
187
191
188
192
names . first
Original file line number Diff line number Diff line change 23
23
24
24
'Valid Vercel' => {
25
25
'VERCEL' => '1' ,
26
- 'VERCEL_URL' => '*.vercel.app' ,
27
26
'VERCEL_REGION' => 'cdg1' ,
28
27
} ,
29
28
Original file line number Diff line number Diff line change 65
65
end
66
66
end
67
67
68
+ context 'when VERCEL and AWS are both given' do
69
+ local_env (
70
+ 'AWS_EXECUTION_ENV' => 'AWS_Lambda_ruby2.7' ,
71
+ 'AWS_REGION' => 'us-east-2' ,
72
+ 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' => '1024' ,
73
+ 'VERCEL' => '1' ,
74
+ 'VERCEL_REGION' => 'cdg1'
75
+ )
76
+
77
+ it_behaves_like 'running in a FaaS environment'
78
+
79
+ it 'prefers vercel' do
80
+ expect ( env . aws? ) . to be false
81
+ expect ( env . vercel? ) . to be true
82
+ expect ( env . fields [ :region ] ) . to be == 'cdg1'
83
+ end
84
+ end
85
+
68
86
context 'when environment is invalid due to missing variable' do
69
87
local_env (
70
88
'AWS_EXECUTION_ENV' => 'AWS_Lambda_ruby2.7' ,
161
179
context 'when FaaS environment is Vercel' do
162
180
local_env (
163
181
'VERCEL' => '1' ,
164
- 'VERCEL_URL' => '*.vercel.app' ,
165
182
'VERCEL_REGION' => 'cdg1'
166
183
)
167
184
168
185
it_behaves_like 'running in a FaaS environment'
169
186
170
187
it 'recognizes Vercel' do
171
188
expect ( env . name ) . to be == 'vercel'
172
- expect ( env . fields [ :url ] ) . to be == '*.vercel.app'
173
189
expect ( env . fields [ :region ] ) . to be == 'cdg1'
174
190
end
175
191
end
You can’t perform that action at this time.
0 commit comments