-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add additional configuration option (#568)
* feat: add additional configuration option * chore: add tests for github webhooks azure functions host builder extensions --------- Co-authored-by: Nick Floyd <[email protected]>
- Loading branch information
Showing
5 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/Octokit.Webhooks.AzureFunctions.Test/GithubWebhookHostBuilderExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
namespace Octokit.Webhooks.AzureFunctions.Test; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
using Xunit; | ||
|
||
public class GithubWebhookHostBuilderExtensionsTests | ||
{ | ||
[Fact] | ||
public void CanConfigureSecretUsingPlainText() | ||
{ | ||
// Arrange | ||
var mockHostBuilder = new Mock<IHostBuilder>(); | ||
var services = new ServiceCollection(); | ||
var testSecret = "test-secret"; | ||
|
||
mockHostBuilder | ||
.Setup(hb => hb.ConfigureServices(It.IsAny<Action<HostBuilderContext, IServiceCollection>>())) | ||
.Callback<Action<HostBuilderContext, IServiceCollection>>((action) => | ||
{ | ||
var context = new HostBuilderContext(new Dictionary<object, object>()); | ||
action(context, services); | ||
}) | ||
.Returns(mockHostBuilder.Object); | ||
|
||
// Act | ||
mockHostBuilder.Object.ConfigureGitHubWebhooks(testSecret); | ||
|
||
// Assert | ||
var serviceProvider = services.BuildServiceProvider(); | ||
var options = serviceProvider.GetRequiredService<IOptions<GitHubWebhooksOptions>>().Value; | ||
Assert.Equal(testSecret, options.Secret); | ||
} | ||
|
||
[Fact] | ||
public void CanConfigureSecretUsingConfigurationInstance() | ||
{ | ||
// Arrange | ||
var mockHostBuilder = new Mock<IHostBuilder>(); | ||
var services = new ServiceCollection(); | ||
var testSecret = "test-secret"; | ||
var configuration = new ConfigurationBuilder() | ||
.AddInMemoryCollection(new Dictionary<string, string?> | ||
{ | ||
["GitHubSecret"] = testSecret, | ||
}) | ||
.Build(); | ||
|
||
mockHostBuilder | ||
.Setup(hb => hb.ConfigureServices(It.IsAny<Action<HostBuilderContext, IServiceCollection>>())) | ||
.Callback<Action<HostBuilderContext, IServiceCollection>>((action) => | ||
{ | ||
var context = new HostBuilderContext(new Dictionary<object, object>()) | ||
{ | ||
Configuration = configuration, | ||
}; | ||
action(context, services); | ||
}) | ||
.Returns(mockHostBuilder.Object); | ||
|
||
static string Configure(IConfiguration config) => config.GetValue<string>("GitHubSecret") | ||
?? throw new ArgumentNullException(); | ||
|
||
// Act | ||
mockHostBuilder.Object.ConfigureGitHubWebhooks(Configure); | ||
|
||
// Assert | ||
var serviceProvider = services.BuildServiceProvider(); | ||
var options = serviceProvider.GetRequiredService<IOptions<GitHubWebhooksOptions>>().Value; | ||
Assert.Equal(testSecret, options.Secret); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/Octokit.Webhooks.AzureFunctions.Test/Octokit.Webhooks.AzureFunctions.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup Label="Build"> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="Project References"> | ||
<ProjectReference Include="..\..\src\Octokit.Webhooks.AzureFunctions\Octokit.Webhooks.AzureFunctions.csproj" /> | ||
<ProjectReference Include="..\Octokit.Webhooks.TestUtils\Octokit.Webhooks.TestUtils.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="Resources\**"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |