Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,6 @@ jobs:
framework: ["net8.0", "net10.0"]
steps:
- uses: actions/checkout@v4
- name: Start Consul
run: |
docker run -d --name consul -p 8500:8500 -p 8600:8600/tcp -p 8600:8600/udp \
hashicorp/consul:1.19 agent -dev -client=0.0.0.0
- name: Wait for Consul
run: sleep 5
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
Expand All @@ -436,14 +430,6 @@ jobs:
--logger "trx;LogFileName=test_results_${{ matrix.provider }}_${{ matrix.framework }}.trx"
--
-parallel none -noshadow
env:
# [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Not a secret")]
# [SuppressMessage("Microsoft.Security", "CSCAN0090:ConfigFile", Justification="Not a secret")]
# [SuppressMessage("Microsoft.Security", "CSCAN0220:DefaultPasswordContexts", Justification="Not a secret")]
ORLEANSCONSULCONNECTIONSTRING: "http://localhost:8500"
- name: Clean up Consul container
if: always()
run: docker rm -f consul
- name: Archive Test Results
if: always()
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -609,7 +595,7 @@ jobs:
- name: Test
run: dotnet test
--framework ${{ matrix.framework }}
--filter "Category=${{ matrix.suite }}"
--filter "Category=${{ matrix.suite }}&Category!=Consul"
--blame-hang-timeout 10m
--logger "trx;LogFileName=test_results_${{ matrix.suite }}_${{ matrix.framework }}.trx"
--
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<PackageVersion Include="System.Memory.Data" Version="8.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="Testcontainers" Version="4.8.1" />
<PackageVersion Include="Testcontainers.Consul" Version="4.8.1" />
<PackageVersion Include="Utf8Json" Version="1.3.7" />
<PackageVersion Include="Verify.Xunit" Version="29.3.1" />
<PackageVersion Include="xunit.assert" Version="2.9.3" />
Expand Down
1 change: 1 addition & 0 deletions test/Extensions/Consul.Tests/Consul.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Testcontainers.Consul" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 22 additions & 12 deletions test/Extensions/Consul.Tests/ConsulTestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net;
using TestExtensions;
using Testcontainers.Consul;
using Xunit;

namespace Consul.Tests
Expand All @@ -9,7 +8,25 @@ namespace Consul.Tests
/// </summary>
public static class ConsulTestUtils
{
public static readonly string ConsulConnectionString = TestDefaultConfiguration.ConsulConnectionString;
private static readonly ConsulContainer _container = new ConsulBuilder()
.WithImage("hashicorp/consul:1.19")
.WithCreateParameterModifier(parameters =>
{
if (parameters.HostConfig is not null)
{
parameters.HostConfig.CapAdd = ["IPC_LOCK"];
}
})
.Build();

public static string ConsulConnectionString
{
get
{
EnsureConsul();
return _container.GetBaseAddress();
}
}
private static readonly Lazy<bool> EnsureConsulLazy = new Lazy<bool>(() => EnsureConsulAsync().Result);

public static void EnsureConsul()
Expand All @@ -20,17 +37,10 @@ public static void EnsureConsul()

public static async Task<bool> EnsureConsulAsync()
{
if (string.IsNullOrWhiteSpace(ConsulConnectionString))
{
return false;
}

try
{
var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(15);
var response = await client.GetAsync($"{ConsulConnectionString}/v1/health/service/consul?pretty");
return response.StatusCode == HttpStatusCode.OK;
await _container.StartAsync();
return true;
Comment thread
Meir017 marked this conversation as resolved.
}
catch (HttpRequestException)
{
Expand Down
Loading