Skip to content

Commit

Permalink
Update user secret tests
Browse files Browse the repository at this point in the history
  • Loading branch information
liliankasem committed Sep 26, 2024
1 parent 9f88ac7 commit ceb44f2
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions test/Azure.Functions.Cli.Tests/E2E/StartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ await CliTester.Run(new RunConfiguration
}, _output);
}

[Theory(Skip = "https://github.com/Azure/azure-functions-core-tools/issues/3644")]
[Theory]
[InlineData("dotnet")]
[InlineData("dotnet-isolated")]
public async Task start_with_user_secrets(string language)
Expand Down Expand Up @@ -689,13 +689,13 @@ await CliTester.Run(new RunConfiguration[]
Dictionary<string, string> userSecrets = new Dictionary<string, string>()
{
{ Constants.AzureWebJobsStorage, "UseDevelopmentStorage=true" },
{ "ConnectionStrings:MyQueueConn", "DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=GMuzNHjlB3S9itqZJHHCnRkrokLkcSyW7yK9BRbGp0ENePunLPwBgpxV1Z/pVo9zpem/2xSHXkMqTHHLcx8XRA==EndpointSuffix=core.windows.net" },
{ "ConnectionStrings:MyQueueConn", "UseDevelopmentStorage=true" },
};
SetUserSecrets(workingDir, userSecrets);
},
Commands = new[]
{
"start --functions http1 --" + language,
"start --functions queue1 --" + language,
},
ExpectExit = false,
OutputContains = new string[]
Expand All @@ -705,19 +705,28 @@ await CliTester.Run(new RunConfiguration[]
CommandTimeout = TimeSpan.FromSeconds(300),
Test = async (workingDir, p) =>
{
using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7071/") })
try
{
await QueueStorageHelper.InsertIntoQueue("myqueue-items", "hello world");
// Give a second for the queue function to trigger
await Task.Delay(1000);
if (_output is Xunit.Sdk.TestOutputHelper testOutputHelper)
{
testOutputHelper.Output.Should().Contain("C# Queue trigger function processed: hello world");
}
}
finally
{
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
var response = await client.GetAsync("/api/http1?name=Test");
response.StatusCode.Should().Be(HttpStatusCode.OK);
p.Kill();
p?.Kill();
}
}
}
}, _output);
}

[Fact(Skip = "Flaky test")]
[Fact]
public async Task start_with_user_secrets_missing_storage()
{
string AzureWebJobsStorageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
Expand Down Expand Up @@ -762,12 +771,11 @@ await CliTester.Run(new RunConfiguration[]
var localSettingsPath = Path.Combine(workingDir, "local.settings.json");
Assert.True(File.Exists(queueCodePath));
_output.WriteLine($"Writing to file {localSettingsPath}");
File.WriteAllText(localSettingsPath, "{ \"IsEncrypted\": false, \"Values\": {} }");
File.WriteAllText(localSettingsPath, "{ \"IsEncrypted\": false, \"Values\": {\""+ Constants.FunctionsWorkerRuntime + "\": \"dotnet\"} }");
// init and set user secrets
Dictionary<string, string> userSecrets = new Dictionary<string, string>()
{
{ Constants.FunctionsWorkerRuntime, "dotnet" },
{ "ConnectionStrings:MyQueueConn", "DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=GMuzNHjlB3S9itqZJHHCnRkrokLkcSyW7yK9BRbGp0ENePunLPwBgpxV1Z/pVo9zpem/2xSHXkMqTHHLcx8XRA==EndpointSuffix=core.windows.net" },
};
SetUserSecrets(workingDir, userSecrets);
Expand All @@ -784,7 +792,7 @@ await CliTester.Run(new RunConfiguration[]
}, _output);
}

[Fact(Skip = "Flaky test")]
[Fact]
public async Task start_with_user_secrets_missing_binding_setting()
{
string AzureWebJobsStorageConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
Expand Down Expand Up @@ -829,13 +837,12 @@ await CliTester.Run(new RunConfiguration[]
var localSettingsPath = Path.Combine(workingDir, "local.settings.json");
Assert.True(File.Exists(queueCodePath));
_output.WriteLine($"Writing to file {localSettingsPath}");
File.WriteAllText(localSettingsPath, "{ \"IsEncrypted\": false, \"Values\": {} }");
File.WriteAllText(localSettingsPath, "{ \"IsEncrypted\": false, \"Values\": {\""+ Constants.FunctionsWorkerRuntime + "\": \"dotnet\"} }");
// init and set user secrets
Dictionary<string, string> userSecrets = new Dictionary<string, string>()
{
{ Constants.AzureWebJobsStorage, "UseDevelopmentStorage=true" },
{ Constants.FunctionsWorkerRuntime, "dotnet" },
};
SetUserSecrets(workingDir, userSecrets);
},
Expand All @@ -851,12 +858,18 @@ await CliTester.Run(new RunConfiguration[]
},
Test = async (workingDir, p) =>
{
using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7071/") })
try
{
using (var client = new HttpClient() { BaseAddress = new Uri("http://localhost:7071/") })
{
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
var response = await client.GetAsync("/api/http1?name=Test");
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
}
finally
{
(await WaitUntilReady(client)).Should().BeTrue(because: _serverNotReady);
var response = await client.GetAsync("/api/http1?name=Test");
response.StatusCode.Should().Be(HttpStatusCode.OK);
p.Kill();
p?.Kill();
}
}
}
Expand Down

0 comments on commit ceb44f2

Please sign in to comment.