Skip to content

Commit

Permalink
Unit tests and fix documentation not being published on package. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
NapalmCodes authored Sep 7, 2024
1 parent 79ed686 commit b31ac0d
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:

- name: Build
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG /p:ContinuousIntegrationBuild=true -p:Version=$BUILD_VERSION

- name: Test
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal

- name: Publish
if: startsWith(github.ref, 'refs/heads/release')
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ jobs:

- name: Build
run: dotnet build $SOLUTION --configuration $BUILD_CONFIG /p:ContinuousIntegrationBuild=true

- name: Test
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,7 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Custom
**/TestResults
**/coveragereport
8 changes: 7 additions & 1 deletion Aspire.Hosting.Krakend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NapalmCodes.Aspire.Hosting.Krakend", "NapalmCodes.Aspire.Hosting.Krakend\NapalmCodes.Aspire.Hosting.Krakend.csproj", "{E8FEC82F-C934-4EA1-99DA-F50EA4287DA4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NapalmCodes.Aspire.Hosting.Krakend", "NapalmCodes.Aspire.Hosting.Krakend\NapalmCodes.Aspire.Hosting.Krakend.csproj", "{E8FEC82F-C934-4EA1-99DA-F50EA4287DA4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{77595ED8-3D80-4049-B593-D877BE38272F}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionF
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NapalmCodes.Aspire.Hosting.Krakend.Tests", "NapalmCodes.Aspire.Hosting.Krakend.Tests\NapalmCodes.Aspire.Hosting.Krakend.Tests.csproj", "{40E4C6F6-4675-4929-AC59-168875D471E8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,6 +24,10 @@ Global
{E8FEC82F-C934-4EA1-99DA-F50EA4287DA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8FEC82F-C934-4EA1-99DA-F50EA4287DA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8FEC82F-C934-4EA1-99DA-F50EA4287DA4}.Release|Any CPU.Build.0 = Release|Any CPU
{40E4C6F6-4675-4929-AC59-168875D471E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40E4C6F6-4675-4929-AC59-168875D471E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40E4C6F6-4675-4929-AC59-168875D471E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40E4C6F6-4675-4929-AC59-168875D471E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
60 changes: 60 additions & 0 deletions NapalmCodes.Aspire.Hosting.Krakend.Tests/AddKrakendTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Sockets;

namespace NapalmCodes.Aspire.Hosting.Krakend.Tests;

public class AddKrakendTests
{
[Fact]
public void AddKrakendContainerAddsAnnotationMetadata()
{
var appBuilder = DistributedApplication.CreateBuilder();

appBuilder.AddKrakend("krakend");

using var app = appBuilder.Build();

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();

var containerResource = Assert.Single(appModel.Resources.OfType<KrakendResource>());
Assert.Equal("krakend", containerResource.Name);

var endpoints = containerResource.Annotations.OfType<EndpointAnnotation>();
Assert.Single(endpoints);

var primaryEndpoint = Assert.Single(endpoints, e => e.Name == "http");
Assert.Equal(8080, primaryEndpoint.TargetPort);
Assert.False(primaryEndpoint.IsExternal);
Assert.Equal("http", primaryEndpoint.Name);
Assert.Null(primaryEndpoint.Port);
Assert.Equal(ProtocolType.Tcp, primaryEndpoint.Protocol);
Assert.Equal("http", primaryEndpoint.Transport);
Assert.Equal("http", primaryEndpoint.UriScheme);

var containerAnnotation = Assert.Single(containerResource.Annotations.OfType<ContainerImageAnnotation>());
Assert.Equal(KrakendContainerImageTags.Tag, containerAnnotation.Tag);
Assert.Equal(KrakendContainerImageTags.Image, containerAnnotation.Image);
Assert.Equal(KrakendContainerImageTags.Registry, containerAnnotation.Registry);
}

[Fact]
public async Task KrakendCreatesConnectionString()
{
var appBuilder = DistributedApplication.CreateBuilder();
var krakend = appBuilder
.AddKrakend("krakend")
.WithEndpoint("http", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 27000));

using var app = appBuilder.Build();

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();

var connectionStringResource = Assert.Single(appModel.Resources.OfType<KrakendResource>()) as IResourceWithConnectionString;
var connectionString = await connectionStringResource.GetConnectionStringAsync();

Assert.Equal($"http://localhost:27000", connectionString);
Assert.Equal("{krakend.bindings.http.url}", connectionStringResource.ConnectionStringExpression.ValueExpression);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NapalmCodes.Aspire.Hosting.Krakend\NapalmCodes.Aspire.Hosting.Krakend.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace NapalmCodes.Aspire.Hosting.Krakend;

internal class KrakendContainerImageTags
internal static class KrakendContainerImageTags
{
public const string Registry = "docker.io";
public const string Image = "devopsfaith/krakend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Title>NapalmCodes.Aspire.Hosting.Krakend</Title>
<Authors>Shawn Vause</Authors>
<Description>Aspire hosting component for the high performance KrakenD (https://www.krakend.io/) API Gateway.</Description>
Expand Down Expand Up @@ -42,4 +43,8 @@
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="NapalmCodes.Aspire.Hosting.Krakend.Tests" />
</ItemGroup>

</Project>

0 comments on commit b31ac0d

Please sign in to comment.