Skip to content

Commit fbb62c8

Browse files
committed
fixing some style issues and removing worker indexing
1 parent 3ad53b9 commit fbb62c8

27 files changed

+133
-143
lines changed

src/Cli/func/Common/Constants.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Collections.ObjectModel;
33
using System.Reflection;
44
using Azure.Functions.Cli.Helpers;
55

66
namespace Azure.Functions.Cli.Common
77
{
8-
internal static class Constants
8+
public static class Constants
99
{
1010
public const string StorageConnectionStringTemplate = "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}";
1111
public const string FunctionsStorageAccountNamePrefix = "AzureFunctions";

test/Cli/Func.E2E.Tests/BaseE2ETests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Azure.Functions.Cli.E2E.Tests
1010
{
1111
public abstract class BaseE2ETests(ITestOutputHelper log) : IAsyncLifetime
1212
{
13-
protected ITestOutputHelper? Log { get; } = log;
13+
protected ITestOutputHelper Log { get; } = log;
1414

1515
protected string FuncPath { get; set; } = Environment.GetEnvironmentVariable(Constants.FuncPath) ?? string.Empty;
1616

test/Cli/Func.E2E.Tests/Commands/FuncStart/AuthTests.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,29 @@ public async Task Start_DotnetIsolated_Test_EnableAuthFeature(
3434
var funcStartCommand = new FuncStartCommand(FuncPath, methodName, Log);
3535
funcStartCommand.ProcessStartedHandler = async (process) =>
3636
{
37-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter, "HttpTrigger");
37+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)), "HttpTrigger");
3838
};
3939

4040
// Build command arguments based on enableAuth parameter
4141
var commandArgs = new List<string> { "start", "--verbose", "--port", port.ToString() };
4242
if (enableAuth)
43+
{
4344
commandArgs.Add("--enableAuth");
45+
}
4446

4547
var result = funcStartCommand
4648
.WithWorkingDirectory(WorkingDirectory)
4749
.Execute(commandArgs.ToArray());
4850

4951
// Validate expected output content
5052
if (string.IsNullOrEmpty(expectedResult))
53+
{
5154
result.Should().HaveStdOutContaining("\"status\": \"401\"");
55+
}
5256
else
57+
{
5358
result.Should().HaveStdOutContaining("Selected out-of-process host.");
59+
}
5460
}
5561
}
5662
}

test/Cli/Func.E2E.Tests/Commands/FuncStart/Core/BaseLogLevelTests.cs

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Azure.Functions.Cli.TestFramework.Commands;
66
using Azure.Functions.Cli.TestFramework.Helpers;
77
using FluentAssertions;
8-
using Func.E2ETests.Traits;
9-
using Xunit;
108
using Xunit.Abstractions;
119

1210
namespace Azure.Functions.Cli.E2E.Tests.Commands.FuncStart.Core
@@ -28,12 +26,11 @@ public async Task RunLogLevelOverridenViaHostJsonTest(string language, string te
2826
string hostJsonContent = "{\"version\": \"2.0\",\"logging\": {\"logLevel\": {\"Default\": \"Debug\"}}}";
2927
File.WriteAllText(hostJsonPath, hostJsonContent);
3028

31-
// Call func start
32-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
29+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
3330

3431
funcStartCommand.ProcessStartedHandler = async (process) =>
3532
{
36-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter);
33+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)));
3734
};
3835

3936
var result = funcStartCommand
@@ -60,11 +57,11 @@ public async Task RunLogLevelOverridenWithFilterTest(string language, string tes
6057
File.WriteAllText(hostJsonPath, hostJsonContent);
6158

6259
// Call func start
63-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
60+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
6461

6562
funcStartCommand.ProcessStartedHandler = async (process) =>
6663
{
67-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter, shouldDelayForLogs: true);
64+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)), shouldDelayForLogs: true);
6865
};
6966

7067
var result = funcStartCommand
@@ -75,7 +72,5 @@ public async Task RunLogLevelOverridenWithFilterTest(string language, string tes
7572
result.Should().HaveStdOutContaining("Found the following functions:");
7673
result.Should().NotHaveStdOutContaining("Reading host configuration file");
7774
}
78-
79-
// Add more shared test methods as needed for LogLevel tests
8075
}
8176
}

test/Cli/Func.E2E.Tests/Commands/FuncStart/Core/BaseMissingConfigTests.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Azure.Functions.Cli.TestFramework.Commands;
66
using Azure.Functions.Cli.TestFramework.Helpers;
77
using FluentAssertions;
8-
using Func.E2ETests.Traits;
9-
using Xunit;
108
using Xunit.Abstractions;
119

1210
namespace Azure.Functions.Cli.E2E.Tests.Commands.FuncStart.Core
@@ -29,7 +27,7 @@ public async Task RunInvalidHostJsonTest(string language, string testName)
2927
File.WriteAllText(hostJsonPath, hostJsonContent);
3028

3129
// Call func start
32-
var result = new FuncStartCommand(FuncPath, testName, Log)
30+
var result = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)))
3331
.WithWorkingDirectory(WorkingDirectory)
3432
.Execute(new[] { "--port", port.ToString() });
3533

@@ -52,7 +50,7 @@ public async Task RunMissingHostJsonTest(string language, string testName)
5250
File.Delete(hostJsonPath);
5351

5452
// Call func start
55-
var result = new FuncStartCommand(FuncPath, testName, Log)
53+
var result = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)))
5654
.WithWorkingDirectory(WorkingDirectory)
5755
.Execute(new[] { "--port", port.ToString() });
5856

@@ -67,7 +65,7 @@ public async Task RunMissingLocalSettingsJsonTest(string language, string runtim
6765
var logFileName = $"{testName}_{language}_{runtimeParameter}";
6866
if (setRuntimeViaEnvironment)
6967
{
70-
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", language);
68+
Environment.SetEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, language);
7169
}
7270

7371
var port = ProcessHelper.GetAvailablePort();
@@ -87,24 +85,28 @@ public async Task RunMissingLocalSettingsJsonTest(string language, string runtim
8785
File.Delete(localSettingsJson);
8886

8987
// Call func start
90-
var funcStartCommand = new FuncStartCommand(FuncPath, logFileName, Log);
88+
var funcStartCommand = new FuncStartCommand(FuncPath, logFileName, Log ?? throw new ArgumentNullException(nameof(Log)));
9189

9290
funcStartCommand.ProcessStartedHandler = async (process) =>
9391
{
94-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter, "HttpTriggerFunc");
92+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)), "HttpTriggerFunc");
9593
};
9694

9795
var startCommand = new List<string> { "--port", port.ToString(), "--verbose" };
9896
if (!string.IsNullOrEmpty(runtimeParameter))
97+
{
9998
startCommand.Add(runtimeParameter);
99+
}
100100

101101
var result = funcStartCommand
102102
.WithWorkingDirectory(WorkingDirectory)
103103
.Execute(startCommand.ToArray());
104104

105105
// Validate output contains expected function URL
106106
if (invokeFunction)
107+
{
107108
result.Should().HaveStdOutContaining("HttpTriggerFunc: [GET,POST] http://localhost:");
109+
}
108110

109111
result.Should().HaveStdOutContaining("Executed 'Functions.HttpTriggerFunc' (Succeeded");
110112
result.Should().HaveStdOutContaining(expectedOutput);
@@ -113,7 +115,9 @@ public async Task RunMissingLocalSettingsJsonTest(string language, string runtim
113115
{
114116
// Clean up environment variable
115117
if (setRuntimeViaEnvironment)
116-
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", null);
118+
{
119+
Environment.SetEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, null);
120+
}
117121
}
118122
}
119123
}

test/Cli/Func.E2E.Tests/Commands/FuncStart/Core/BaseUserSecretsTests.cs

+31-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Azure.Functions.Cli.TestFramework.Commands;
77
using Azure.Functions.Cli.TestFramework.Helpers;
88
using FluentAssertions;
9-
using Func.E2ETests.Traits;
109
using Xunit;
1110
using Xunit.Abstractions;
1211

@@ -48,13 +47,13 @@ public async Task RunUserSecretsTest(string language, string testName)
4847
SetupUserSecrets(userSecrets);
4948

5049
// Call func start
51-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
50+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
5251

5352
funcStartCommand.ProcessStartedHandler = async (process) =>
5453
{
5554
try
5655
{
57-
await ProcessHelper.WaitForFunctionHostToStart(process, port, funcStartCommand.FileWriter);
56+
await ProcessHelper.WaitForFunctionHostToStart(process, port, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)));
5857

5958
// Insert message into queue
6059
await QueueStorageHelper.InsertIntoQueue("myqueue-items", "hello world");
@@ -78,7 +77,7 @@ public async Task RunMissingStorageConnString_FailsWithExpectedError(string lang
7877
var azureWebJobsStorage = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
7978
if (!string.IsNullOrEmpty(azureWebJobsStorage))
8079
{
81-
Log.WriteLine("Skipping test as AzureWebJobsStorage is set");
80+
Log?.WriteLine("Skipping test as AzureWebJobsStorage is set");
8281
return;
8382
}
8483

@@ -113,7 +112,7 @@ public async Task RunMissingStorageConnString_FailsWithExpectedError(string lang
113112
SetupUserSecrets(userSecrets);
114113

115114
// 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)))
117116
.WithWorkingDirectory(WorkingDirectory)
118117
.Execute(new[] { "start", "--functions", "http1", "--port", port.ToString() });
119118

@@ -127,7 +126,7 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
127126
var azureWebJobsStorage = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
128127
if (!string.IsNullOrEmpty(azureWebJobsStorage))
129128
{
130-
Log.WriteLine("Skipping test as AzureWebJobsStorage is set");
129+
Log?.WriteLine("Skipping test as AzureWebJobsStorage is set");
131130
return;
132131
}
133132

@@ -150,7 +149,7 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
150149

151150
// Clear local.settings.json
152151
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 + "\"} }";
154153
File.WriteAllText(settingsPath, settingsContent);
155154

156155
// Set up user secrets with AzureWebJobsStorage but missing MyQueueConn
@@ -162,11 +161,11 @@ public async Task RunWithUserSecrets_MissingBindingSetting_FailsWithExpectedErro
162161
SetupUserSecrets(userSecrets);
163162

164163
// Call func start
165-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
164+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
166165

167166
funcStartCommand.ProcessStartedHandler = async (process) =>
168167
{
169-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter);
168+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)));
170169
};
171170

172171
var result = funcStartCommand
@@ -191,7 +190,9 @@ private void SetupUserSecrets(Dictionary<string, string> secrets)
191190
};
192191

193192
using (var process = Process.Start(initProcess))
193+
{
194194
process?.WaitForExit();
195+
}
195196

196197
// Set each secret
197198
foreach (var secret in secrets)
@@ -206,7 +207,9 @@ private void SetupUserSecrets(Dictionary<string, string> secrets)
206207
};
207208

208209
using (var process = Process.Start(setProcess))
210+
{
209211
process?.WaitForExit();
212+
}
210213
}
211214
}
212215

@@ -221,7 +224,9 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
221224
var methodName = nameof(Start_MissingLocalSettingsJson_BehavesAsExpected);
222225
var logFileName = $"{methodName}_{language}_{runtimeParameter}";
223226
if (setRuntimeViaEnvironment)
224-
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "dotnet-isolated");
227+
{
228+
Environment.SetEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, "dotnet-isolated");
229+
}
225230

226231
var port = ProcessHelper.GetAvailablePort();
227232

@@ -240,32 +245,38 @@ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected(string langua
240245
File.Delete(localSettingsJson);
241246

242247
// Call func start
243-
var funcStartCommand = new FuncStartCommand(FuncPath, logFileName, Log);
248+
var funcStartCommand = new FuncStartCommand(FuncPath, logFileName, Log ?? throw new ArgumentNullException(nameof(Log)));
244249

245250
funcStartCommand.ProcessStartedHandler = async (process) =>
246251
{
247-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter, "HttpTriggerFunc");
252+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)), "HttpTriggerFunc");
248253
};
249254

250255
var startCommand = new List<string> { "--port", port.ToString(), "--verbose" };
251256
if (!string.IsNullOrEmpty(runtimeParameter))
257+
{
252258
startCommand.Add(runtimeParameter);
259+
}
253260

254261
var result = funcStartCommand
255262
.WithWorkingDirectory(WorkingDirectory)
256263
.Execute(startCommand.ToArray());
257264

258265
// Validate output contains expected function URL
259266
if (invokeFunction)
267+
{
260268
result.Should().HaveStdOutContaining("HttpTriggerFunc: [GET,POST] http://localhost:");
269+
}
261270

262271
result.Should().HaveStdOutContaining("Executed 'Functions.HttpTriggerFunc' (Succeeded");
263272
}
264273
finally
265274
{
266275
// Clean up environment variable
267276
if (setRuntimeViaEnvironment)
268-
Environment.SetEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", null);
277+
{
278+
Environment.SetEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, null);
279+
}
269280
}
270281
}
271282

@@ -289,16 +300,16 @@ public async Task Start_LanguageWorker_InvalidFunctionJson_FailsWithExpectedErro
289300
await File.WriteAllTextAsync(filePath, functionJson);
290301

291302
// Call func start
292-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
303+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
293304

294305
funcStartCommand.ProcessStartedHandler = async (process) =>
295306
{
296-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter);
307+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)));
297308
};
298309

299310
var result = funcStartCommand
300311
.WithWorkingDirectory(WorkingDirectory)
301-
.WithEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "node")
312+
.WithEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, "node")
302313
.Execute(new[] { "--port", port.ToString(), "--verbose" });
303314

304315
// Validate error message
@@ -318,7 +329,7 @@ public async Task Start_EmptyEnvVars_HandledAsExpected()
318329
await FuncNewWithRetryAsync(testName, new[] { ".", "--template", "Httptrigger", "--name", "HttpTrigger", "--language", "node" }, workerRuntime: "node");
319330

320331
// Add empty setting
321-
var funcSettingsResult = new FuncSettingsCommand(FuncPath, testName, Log)
332+
var funcSettingsResult = new FuncSettingsCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)))
322333
.WithWorkingDirectory(WorkingDirectory)
323334
.Execute(new[] { "add", "emptySetting", "EMPTY_VALUE" });
324335
funcSettingsResult.Should().ExitWith(0);
@@ -330,16 +341,16 @@ public async Task Start_EmptyEnvVars_HandledAsExpected()
330341
File.WriteAllText(settingsPath, settingsContent);
331342

332343
// Call func start
333-
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log);
344+
var funcStartCommand = new FuncStartCommand(FuncPath, testName, Log ?? throw new ArgumentNullException(nameof(Log)));
334345

335346
funcStartCommand.ProcessStartedHandler = async (process) =>
336347
{
337-
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter);
348+
await ProcessHelper.ProcessStartedHandlerHelper(port, process, funcStartCommand.FileWriter ?? throw new ArgumentNullException(nameof(funcStartCommand.FileWriter)));
338349
};
339350

340351
var result = funcStartCommand
341352
.WithWorkingDirectory(WorkingDirectory)
342-
.WithEnvironmentVariable("FUNCTIONS_WORKER_RUNTIME", "node")
353+
.WithEnvironmentVariable(Common.Constants.FunctionsWorkerRuntime, "node")
343354
.Execute(new[] { "--port", port.ToString(), "--verbose" });
344355

345356
// Validate function works and doesn't show skipping message

0 commit comments

Comments
 (0)