1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the MIT License. See License.txt in the project root for license information.
3
3
4
+ using Azure . Functions . Cli . E2E . Tests ;
4
5
using FluentAssertions ;
5
6
using Func . E2ETests . Traits ;
6
7
using Func . TestFramework . Assertions ;
9
10
using Xunit ;
10
11
using Xunit . Abstractions ;
11
12
12
- namespace Func . E2ETests . Commands . FuncStart
13
+ namespace Azure . Functions . Cli . E2E . Tests . Commands . FuncStart
13
14
{
14
- public class MissingConfigTests : BaseE2ETests
15
+ public class MissingConfigTests ( ITestOutputHelper log ) : BaseE2ETests ( log )
15
16
{
16
- public MissingConfigTests ( ITestOutputHelper log )
17
- : base ( log )
18
- {
19
- }
20
-
21
17
[ Fact ]
22
18
[ Trait ( TestTraits . Group , TestTraits . RequiresNestedInProcArtifacts ) ]
23
19
public async Task Start_InProc_InvalidHostJson_FailsWithExpectedError ( )
24
20
{
25
21
int port = ProcessHelper . GetAvailablePort ( ) ;
26
- string testName = "Start_InProc_InvalidHostJson_FailsWithExpectedError" ;
22
+ var testName = "Start_InProc_InvalidHostJson_FailsWithExpectedError" ;
27
23
28
24
// Initialize dotnet function app using retry helper
29
25
await FuncInitWithRetryAsync ( testName , new [ ] { "." , "--worker-runtime" , "dotnet" } ) ;
@@ -32,8 +28,8 @@ public async Task Start_InProc_InvalidHostJson_FailsWithExpectedError()
32
28
await FuncNewWithRetryAsync ( testName , new [ ] { "." , "--template" , "Httptrigger" , "--name" , "HttpTriggerCSharp" } ) ;
33
29
34
30
// Create invalid host.json
35
- string hostJsonPath = Path . Combine ( WorkingDirectory , "host.json" ) ;
36
- string hostJsonContent = "{ \" version\" : \" 2.0\" , \" extensionBundle\" : { \" id\" : \" Microsoft.Azure.Functions.ExtensionBundle\" , \" version\" : \" [2.*, 3.0.0)\" }}" ;
31
+ var hostJsonPath = Path . Combine ( WorkingDirectory , "host.json" ) ;
32
+ var hostJsonContent = "{ \" version\" : \" 2.0\" , \" extensionBundle\" : { \" id\" : \" Microsoft.Azure.Functions.ExtensionBundle\" , \" version\" : \" [2.*, 3.0.0)\" }}" ;
37
33
File . WriteAllText ( hostJsonPath , hostJsonContent ) ;
38
34
39
35
// Call func start
@@ -50,7 +46,7 @@ public async Task Start_InProc_InvalidHostJson_FailsWithExpectedError()
50
46
public async Task Start_InProc_MissingHostJson_FailsWithExpectedError ( )
51
47
{
52
48
int port = ProcessHelper . GetAvailablePort ( ) ;
53
- string testName = "Start_InProc_MissingHostJson_FailsWithExpectedError" ;
49
+ var testName = "Start_InProc_MissingHostJson_FailsWithExpectedError" ;
54
50
55
51
// Initialize dotnet function app using retry helper
56
52
await FuncInitWithRetryAsync ( testName , new [ ] { "." , "--worker-runtime" , "dotnet" } ) ;
@@ -59,7 +55,7 @@ public async Task Start_InProc_MissingHostJson_FailsWithExpectedError()
59
55
await FuncNewWithRetryAsync ( testName , new [ ] { "." , "--template" , "Httptrigger" , "--name" , "HttpTriggerCSharp" } ) ;
60
56
61
57
// Delete host.json
62
- string hostJsonPath = Path . Combine ( WorkingDirectory , "host.json" ) ;
58
+ var hostJsonPath = Path . Combine ( WorkingDirectory , "host.json" ) ;
63
59
File . Delete ( hostJsonPath ) ;
64
60
65
61
// Call func start
@@ -79,12 +75,10 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
79
75
{
80
76
try
81
77
{
82
- string methodName = "Start_MissingLocalSettingsJson_BehavesAsExpected" ;
83
- string logFileName = $ "{ methodName } _{ language } _{ runtimeParameter } ";
78
+ var methodName = "Start_MissingLocalSettingsJson_BehavesAsExpected" ;
79
+ var logFileName = $ "{ methodName } _{ language } _{ runtimeParameter } ";
84
80
if ( setRuntimeViaEnvironment )
85
- {
86
81
Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "dotnet-isolated" ) ;
87
- }
88
82
89
83
int port = ProcessHelper . GetAvailablePort ( ) ;
90
84
@@ -112,29 +106,23 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
112
106
113
107
var startCommand = new List < string > { "--port" , port . ToString ( ) , "--verbose" } ;
114
108
if ( ! string . IsNullOrEmpty ( runtimeParameter ) )
115
- {
116
109
startCommand . Add ( runtimeParameter ) ;
117
- }
118
110
119
111
var result = funcStartCommand
120
112
. WithWorkingDirectory ( WorkingDirectory )
121
113
. Execute ( startCommand . ToArray ( ) ) ;
122
114
123
115
// Validate output contains expected function URL
124
116
if ( invokeFunction )
125
- {
126
117
result . Should ( ) . HaveStdOutContaining ( "HttpTriggerFunc: [GET,POST] http://localhost:" ) ;
127
- }
128
118
129
119
result . Should ( ) . HaveStdOutContaining ( "Executed 'Functions.HttpTriggerFunc' (Succeeded" ) ;
130
120
}
131
121
finally
132
122
{
133
123
// Clean up environment variable
134
124
if ( setRuntimeViaEnvironment )
135
- {
136
125
Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , null ) ;
137
- }
138
126
}
139
127
}
140
128
@@ -143,7 +131,7 @@ public async Task Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedErro
143
131
{
144
132
int port = ProcessHelper . GetAvailablePort ( ) ;
145
133
var functionName = "HttpTriggerJS" ;
146
- string testName = "Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedError" ;
134
+ var testName = "Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedError" ;
147
135
148
136
// Initialize Node.js function app using retry helper
149
137
await FuncInitWithRetryAsync ( testName , new [ ] { "." , "--worker-runtime" , "node" , "-m" , "v3" } ) ;
@@ -178,7 +166,7 @@ public async Task Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedErro
178
166
public async Task Start_EmptyEnvVars_HandledAsExpected ( )
179
167
{
180
168
int port = ProcessHelper . GetAvailablePort ( ) ;
181
- string testName = "Start_EmptyEnvVars_HandledAsExpected" ;
169
+ var testName = "Start_EmptyEnvVars_HandledAsExpected" ;
182
170
183
171
// Initialize Node.js function app using retry helper
184
172
await FuncInitWithRetryAsync ( testName , new [ ] { "." , "--worker-runtime" , "node" , "-m" , "v4" } ) ;
@@ -193,8 +181,8 @@ public async Task Start_EmptyEnvVars_HandledAsExpected()
193
181
funcSettingsResult . Should ( ) . ExitWith ( 0 ) ;
194
182
195
183
// Modify settings file to have empty value
196
- string settingsPath = Path . Combine ( WorkingDirectory , "local.settings.json" ) ;
197
- string settingsContent = File . ReadAllText ( settingsPath ) ;
184
+ var settingsPath = Path . Combine ( WorkingDirectory , "local.settings.json" ) ;
185
+ var settingsContent = File . ReadAllText ( settingsPath ) ;
198
186
settingsContent = settingsContent . Replace ( "EMPTY_VALUE" , string . Empty ) ;
199
187
File . WriteAllText ( settingsPath , settingsContent ) ;
200
188
0 commit comments