6
6
using Azure . Functions . Cli . TestFramework . Commands ;
7
7
using Azure . Functions . Cli . TestFramework . Helpers ;
8
8
using FluentAssertions ;
9
- using Func . E2ETests . Traits ;
10
9
using Xunit ;
11
10
using Xunit . Abstractions ;
12
11
@@ -48,13 +47,13 @@ public async Task RunUserSecretsTest(string language, string testName)
48
47
SetupUserSecrets ( userSecrets ) ;
49
48
50
49
// Call func start
51
- var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ) ;
50
+ var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) ) ;
52
51
53
52
funcStartCommand . ProcessStartedHandler = async ( process ) =>
54
53
{
55
54
try
56
55
{
57
- await ProcessHelper . WaitForFunctionHostToStart ( process , port , funcStartCommand . FileWriter ) ;
56
+ await ProcessHelper . WaitForFunctionHostToStart ( process , port , funcStartCommand . FileWriter ?? throw new ArgumentNullException ( nameof ( funcStartCommand . FileWriter ) ) ) ;
58
57
59
58
// Insert message into queue
60
59
await QueueStorageHelper . InsertIntoQueue ( "myqueue-items" , "hello world" ) ;
@@ -78,7 +77,7 @@ public async Task RunMissingStorageConnString_FailsWithExpectedError(string lang
78
77
var azureWebJobsStorage = Environment . GetEnvironmentVariable ( "AzureWebJobsStorage" ) ;
79
78
if ( ! string . IsNullOrEmpty ( azureWebJobsStorage ) )
80
79
{
81
- Log . WriteLine ( "Skipping test as AzureWebJobsStorage is set" ) ;
80
+ Log ? . WriteLine ( "Skipping test as AzureWebJobsStorage is set" ) ;
82
81
return ;
83
82
}
84
83
@@ -113,7 +112,7 @@ public async Task RunMissingStorageConnString_FailsWithExpectedError(string lang
113
112
SetupUserSecrets ( userSecrets ) ;
114
113
115
114
// Call func start for HTTP function only
116
- var result = new FuncStartCommand ( FuncPath , testName , Log )
115
+ var result = new FuncStartCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) )
117
116
. WithWorkingDirectory ( WorkingDirectory )
118
117
. Execute ( new [ ] { "start" , "--functions" , "http1" , "--port" , port . ToString ( ) } ) ;
119
118
@@ -127,7 +126,7 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
127
126
var azureWebJobsStorage = Environment . GetEnvironmentVariable ( "AzureWebJobsStorage" ) ;
128
127
if ( ! string . IsNullOrEmpty ( azureWebJobsStorage ) )
129
128
{
130
- Log . WriteLine ( "Skipping test as AzureWebJobsStorage is set" ) ;
129
+ Log ? . WriteLine ( "Skipping test as AzureWebJobsStorage is set" ) ;
131
130
return ;
132
131
}
133
132
@@ -150,7 +149,7 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
150
149
151
150
// Clear local.settings.json
152
151
var settingsPath = Path . Combine ( WorkingDirectory , "local.settings.json" ) ;
153
- var settingsContent = "{ \" IsEncrypted\" : false, \" Values\" : { \" FUNCTIONS_WORKER_RUNTIME\" : \" " + languageWorker + "\" } }" ; ;
152
+ var settingsContent = "{ \" IsEncrypted\" : false, \" Values\" : { \" FUNCTIONS_WORKER_RUNTIME\" : \" " + languageWorker + "\" } }" ;
154
153
File . WriteAllText ( settingsPath , settingsContent ) ;
155
154
156
155
// Set up user secrets with AzureWebJobsStorage but missing MyQueueConn
@@ -162,11 +161,11 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
162
161
SetupUserSecrets ( userSecrets ) ;
163
162
164
163
// Call func start
165
- var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ) ;
164
+ var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) ) ;
166
165
167
166
funcStartCommand . ProcessStartedHandler = async ( process ) =>
168
167
{
169
- await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ) ;
168
+ await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ?? throw new ArgumentNullException ( nameof ( funcStartCommand . FileWriter ) ) ) ;
170
169
} ;
171
170
172
171
var result = funcStartCommand
@@ -191,7 +190,9 @@ private void SetupUserSecrets(Dictionary<string, string> secrets)
191
190
} ;
192
191
193
192
using ( var process = Process . Start ( initProcess ) )
193
+ {
194
194
process ? . WaitForExit ( ) ;
195
+ }
195
196
196
197
// Set each secret
197
198
foreach ( var secret in secrets )
@@ -206,7 +207,9 @@ private void SetupUserSecrets(Dictionary<string, string> secrets)
206
207
} ;
207
208
208
209
using ( var process = Process . Start ( setProcess ) )
210
+ {
209
211
process ? . WaitForExit ( ) ;
212
+ }
210
213
}
211
214
}
212
215
@@ -221,7 +224,9 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
221
224
var methodName = nameof ( Start_MissingLocalSettingsJson_BehavesAsExpected ) ;
222
225
var logFileName = $ "{ methodName } _{ language } _{ runtimeParameter } ";
223
226
if ( setRuntimeViaEnvironment )
224
- Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "dotnet-isolated" ) ;
227
+ {
228
+ Environment . SetEnvironmentVariable ( Common . Constants . FunctionsWorkerRuntime , "dotnet-isolated" ) ;
229
+ }
225
230
226
231
var port = ProcessHelper . GetAvailablePort ( ) ;
227
232
@@ -240,32 +245,38 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
240
245
File . Delete ( localSettingsJson ) ;
241
246
242
247
// Call func start
243
- var funcStartCommand = new FuncStartCommand ( FuncPath , logFileName , Log ) ;
248
+ var funcStartCommand = new FuncStartCommand ( FuncPath , logFileName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) ) ;
244
249
245
250
funcStartCommand . ProcessStartedHandler = async ( process ) =>
246
251
{
247
- await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter , "HttpTriggerFunc" ) ;
252
+ await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ?? throw new ArgumentNullException ( nameof ( funcStartCommand . FileWriter ) ) , "HttpTriggerFunc" ) ;
248
253
} ;
249
254
250
255
var startCommand = new List < string > { "--port" , port . ToString ( ) , "--verbose" } ;
251
256
if ( ! string . IsNullOrEmpty ( runtimeParameter ) )
257
+ {
252
258
startCommand . Add ( runtimeParameter ) ;
259
+ }
253
260
254
261
var result = funcStartCommand
255
262
. WithWorkingDirectory ( WorkingDirectory )
256
263
. Execute ( startCommand . ToArray ( ) ) ;
257
264
258
265
// Validate output contains expected function URL
259
266
if ( invokeFunction )
267
+ {
260
268
result . Should ( ) . HaveStdOutContaining ( "HttpTriggerFunc: [GET,POST] http://localhost:" ) ;
269
+ }
261
270
262
271
result . Should ( ) . HaveStdOutContaining ( "Executed 'Functions.HttpTriggerFunc' (Succeeded" ) ;
263
272
}
264
273
finally
265
274
{
266
275
// Clean up environment variable
267
276
if ( setRuntimeViaEnvironment )
268
- Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , null ) ;
277
+ {
278
+ Environment . SetEnvironmentVariable ( Common . Constants . FunctionsWorkerRuntime , null ) ;
279
+ }
269
280
}
270
281
}
271
282
@@ -289,16 +300,16 @@ public async Task Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedErro
289
300
await File . WriteAllTextAsync ( filePath , functionJson ) ;
290
301
291
302
// Call func start
292
- var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ) ;
303
+ var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) ) ;
293
304
294
305
funcStartCommand . ProcessStartedHandler = async ( process ) =>
295
306
{
296
- await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ) ;
307
+ await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ?? throw new ArgumentNullException ( nameof ( funcStartCommand . FileWriter ) ) ) ;
297
308
} ;
298
309
299
310
var result = funcStartCommand
300
311
. WithWorkingDirectory ( WorkingDirectory )
301
- . WithEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "node" )
312
+ . WithEnvironmentVariable ( Common . Constants . FunctionsWorkerRuntime , "node" )
302
313
. Execute ( new [ ] { "--port" , port . ToString ( ) , "--verbose" } ) ;
303
314
304
315
// Validate error message
@@ -318,7 +329,7 @@ public async Task Start_EmptyEnvVars_HandledAsExpected()
318
329
await FuncNewWithRetryAsync ( testName , new [ ] { "." , "--template" , "Httptrigger" , "--name" , "HttpTrigger" , "--language" , "node" } , workerRuntime : "node" ) ;
319
330
320
331
// Add empty setting
321
- var funcSettingsResult = new FuncSettingsCommand ( FuncPath , testName , Log )
332
+ var funcSettingsResult = new FuncSettingsCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) )
322
333
. WithWorkingDirectory ( WorkingDirectory )
323
334
. Execute ( new [ ] { "add" , "emptySetting" , "EMPTY_VALUE" } ) ;
324
335
funcSettingsResult . Should ( ) . ExitWith ( 0 ) ;
@@ -330,16 +341,16 @@ public async Task Start_EmptyEnvVars_HandledAsExpected()
330
341
File . WriteAllText ( settingsPath , settingsContent ) ;
331
342
332
343
// Call func start
333
- var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ) ;
344
+ var funcStartCommand = new FuncStartCommand ( FuncPath , testName , Log ?? throw new ArgumentNullException ( nameof ( Log ) ) ) ;
334
345
335
346
funcStartCommand . ProcessStartedHandler = async ( process ) =>
336
347
{
337
- await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ) ;
348
+ await ProcessHelper . ProcessStartedHandlerHelper ( port , process , funcStartCommand . FileWriter ?? throw new ArgumentNullException ( nameof ( funcStartCommand . FileWriter ) ) ) ;
338
349
} ;
339
350
340
351
var result = funcStartCommand
341
352
. WithWorkingDirectory ( WorkingDirectory )
342
- . WithEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "node" )
353
+ . WithEnvironmentVariable ( Common . Constants . FunctionsWorkerRuntime , "node" )
343
354
. Execute ( new [ ] { "--port" , port . ToString ( ) , "--verbose" } ) ;
344
355
345
356
// Validate function works and doesn't show skipping message
0 commit comments