Skip to content

Commit 085f0ec

Browse files
Hamilton, MontaneHamilton, Montane
Hamilton, Montane
authored and
Hamilton, Montane
committed
Add Seq Module
1 parent dfb9f41 commit 085f0ec

12 files changed

+257
-3
lines changed

Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
<!-- Unit and integration test dependencies: -->
1818
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
1919
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.9.1"/>
20+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1"/>
2021
<PackageVersion Include="coverlet.collector" Version="6.0.2"/>
22+
<PackageVersion Include="Seq.Api" Version="2024.3.0"/>
23+
<PackageVersion Include="Seq.Extensions.Logging" Version="8.0.0"/>
2124
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
2225
<PackageVersion Include="xunit" Version="2.9.0"/>
2326
<!-- Third-party client dependencies to connect and interact with the containers: -->

Testcontainers.sln

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes
195195
EndProject
196196
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}"
197197
EndProject
198+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq", "src\Testcontainers.Seq\Testcontainers.Seq.csproj", "{7AC5C1F7-1469-4E5C-AF24-08F22012049E}"
199+
EndProject
200+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq.Tests", "tests\Testcontainers.Seq.Tests\Testcontainers.Seq.Tests.csproj", "{14402644-8592-4A99-AD5F-F141DE0A4A8F}"
201+
EndProject
198202
Global
199203
GlobalSection(SolutionConfigurationPlatforms) = preSolution
200204
Debug|Any CPU = Debug|Any CPU
201205
Release|Any CPU = Release|Any CPU
202206
EndGlobalSection
203-
GlobalSection(SolutionProperties) = preSolution
204-
HideSolutionNode = FALSE
205-
EndGlobalSection
206207
GlobalSection(ProjectConfigurationPlatforms) = postSolution
207208
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
208209
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -568,6 +569,17 @@ Global
568569
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
569570
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
570571
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU
572+
{7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
573+
{7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Debug|Any CPU.Build.0 = Debug|Any CPU
574+
{7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Release|Any CPU.ActiveCfg = Release|Any CPU
575+
{7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Release|Any CPU.Build.0 = Release|Any CPU
576+
{14402644-8592-4A99-AD5F-F141DE0A4A8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
577+
{14402644-8592-4A99-AD5F-F141DE0A4A8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
578+
{14402644-8592-4A99-AD5F-F141DE0A4A8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
579+
{14402644-8592-4A99-AD5F-F141DE0A4A8F}.Release|Any CPU.Build.0 = Release|Any CPU
580+
EndGlobalSection
581+
GlobalSection(SolutionProperties) = preSolution
582+
HideSolutionNode = FALSE
571583
EndGlobalSection
572584
GlobalSection(NestedProjects) = preSolution
573585
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
@@ -661,5 +673,7 @@ Global
661673
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
662674
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
663675
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
676+
{7AC5C1F7-1469-4E5C-AF24-08F22012049E} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
677+
{14402644-8592-4A99-AD5F-F141DE0A4A8F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
664678
EndGlobalSection
665679
EndGlobal

src/Testcontainers.Seq/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root = true

src/Testcontainers.Seq/SeqBuilder.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
namespace Testcontainers.Seq;
2+
3+
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
4+
[PublicAPI]
5+
public sealed class SeqBuilder : ContainerBuilder<SeqBuilder, SeqContainer, SeqConfiguration>
6+
{
7+
public const string SeqImage = "datalust/seq:2024.2.11456";
8+
9+
public const ushort SeqApiPort = 80;
10+
public const ushort SeqIngestionPort = 5341;
11+
12+
/// <inheritdoc />
13+
protected override SeqConfiguration DockerResourceConfiguration { get; }
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="SeqBuilder" /> class.
17+
/// </summary>
18+
public SeqBuilder()
19+
: this(new SeqConfiguration())
20+
{
21+
DockerResourceConfiguration = Init().DockerResourceConfiguration;
22+
}
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="SeqBuilder" /> class.
26+
/// </summary>
27+
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
28+
private SeqBuilder(SeqConfiguration resourceConfiguration)
29+
: base(resourceConfiguration)
30+
{
31+
DockerResourceConfiguration = resourceConfiguration;
32+
}
33+
34+
/// <inheritdoc />
35+
public override SeqContainer Build()
36+
{
37+
Validate();
38+
return new SeqContainer(DockerResourceConfiguration);
39+
}
40+
/// <inheritdoc />
41+
protected override SeqBuilder Init()
42+
{
43+
return base.Init()
44+
.WithImage(SeqImage)
45+
.WithPortBinding(SeqApiPort, true)
46+
.WithPortBinding(SeqIngestionPort, true)
47+
.WithEnvironment(new Dictionary<string, string>
48+
{
49+
{"ACCEPT_EULA", "Y" }
50+
})
51+
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
52+
request.ForPath("/health").ForPort(SeqApiPort)));
53+
}
54+
55+
/// <inheritdoc />
56+
protected override SeqBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
57+
{
58+
return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration));
59+
}
60+
61+
/// <inheritdoc />
62+
protected override SeqBuilder Clone(IContainerConfiguration resourceConfiguration)
63+
{
64+
return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration));
65+
}
66+
67+
/// <inheritdoc />
68+
protected override SeqBuilder Merge(SeqConfiguration oldValue, SeqConfiguration newValue)
69+
{
70+
return new SeqBuilder(new SeqConfiguration(oldValue, newValue));
71+
}
72+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace Testcontainers.Seq;
2+
3+
/// <inheritdoc cref="ContainerConfiguration" />
4+
[PublicAPI]
5+
public sealed class SeqConfiguration : ContainerConfiguration
6+
{
7+
/// <summary>
8+
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
9+
/// </summary>
10+
/// <param name="config">The Orion.TestContainers.Seq config.</param>
11+
public SeqConfiguration(object config = null)
12+
{
13+
// Sets the custom builder methods property values.
14+
}
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
18+
/// </summary>
19+
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
20+
public SeqConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
21+
: base(resourceConfiguration)
22+
{
23+
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
24+
}
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
28+
/// </summary>
29+
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
30+
public SeqConfiguration(IContainerConfiguration resourceConfiguration)
31+
: base(resourceConfiguration)
32+
{
33+
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
34+
}
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
38+
/// </summary>
39+
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
40+
public SeqConfiguration(SeqConfiguration resourceConfiguration)
41+
: this(new SeqConfiguration(), resourceConfiguration)
42+
{
43+
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
44+
}
45+
46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
48+
/// </summary>
49+
/// <param name="oldValue">The old Docker resource configuration.</param>
50+
/// <param name="newValue">The new Docker resource configuration.</param>
51+
public SeqConfiguration(SeqConfiguration oldValue, SeqConfiguration newValue)
52+
: base(oldValue, newValue)
53+
{
54+
// Create an updated immutable copy of the module configuration.
55+
}
56+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Testcontainers.Seq;
4+
5+
/// <inheritdoc cref="DockerContainer" />
6+
[PublicAPI]
7+
public sealed class SeqContainer : DockerContainer
8+
{
9+
/// <summary>
10+
/// Initializes a new instance of the <see cref="SeqContainer" /> class.
11+
/// </summary>
12+
/// <param name="configuration">The container configuration.</param>
13+
public SeqContainer(SeqConfiguration configuration)
14+
: base(configuration)
15+
{
16+
}
17+
18+
public string GetServerApiUrl()
19+
{
20+
return new UriBuilder("http", Hostname, GetMappedPublicPort(SeqBuilder.SeqApiPort)).Uri.ToString();
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
8+
</ItemGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
11+
</ItemGroup>
12+
</Project>

src/Testcontainers.Seq/Usings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using System.Collections.Generic;
2+
global using Docker.DotNet.Models;
3+
global using DotNet.Testcontainers.Builders;
4+
global using DotNet.Testcontainers.Configurations;
5+
global using DotNet.Testcontainers.Containers;
6+
global using JetBrains.Annotations;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root = true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.Extensions.Logging;
2+
using Seq.Api;
3+
using System;
4+
using System.Linq;
5+
6+
namespace Testcontainers.Seq;
7+
8+
public sealed class SeqContainerTest : IAsyncLifetime
9+
{
10+
private readonly SeqContainer _seqContainer = new SeqBuilder().Build();
11+
12+
public Task InitializeAsync()
13+
{
14+
return _seqContainer.StartAsync();
15+
}
16+
17+
public Task DisposeAsync()
18+
{
19+
return _seqContainer.DisposeAsync().AsTask();
20+
}
21+
22+
[Fact]
23+
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
24+
public async Task CanLog()
25+
{
26+
var currentSeqApiPort = _seqContainer.GetMappedPublicPort(80);
27+
var currentSeqHostname = _seqContainer.Hostname;
28+
29+
ILoggerFactory loggerFactory = new LoggerFactory();
30+
loggerFactory.AddSeq(_seqContainer.GetServerApiUrl());
31+
var testLogger = loggerFactory.CreateLogger("testlogger");
32+
testLogger.LogInformation("TRY THIS");
33+
34+
var seqConnection = new SeqConnection(_seqContainer.GetServerApiUrl());
35+
var eventList = await seqConnection.Events.ListAsync(fromDateUtc: DateTime.Now.AddMinutes(-1));
36+
Assert.Contains(eventList, e => e.MessageTemplateTokens.Last().Text == "TRY THIS");
37+
}
38+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net8.0</TargetFrameworks>
4+
<IsPackable>false</IsPackable>
5+
<IsPublishable>false</IsPublishable>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="coverlet.collector">
9+
<PrivateAssets>all</PrivateAssets>
10+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
11+
</PackageReference>
12+
<PackageReference Include="Microsoft.Extensions.Logging" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14+
<PackageReference Include="Seq.Api" />
15+
<PackageReference Include="Seq.Extensions.Logging" />
16+
<PackageReference Include="xunit" />
17+
<PackageReference Include="xunit.runner.visualstudio">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\src\Testcontainers.Seq\Testcontainers.Seq.csproj" />
24+
<ProjectReference Include="..\Testcontainers.Commons\Testcontainers.Commons.csproj" />
25+
</ItemGroup>
26+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global using System.Threading.Tasks;
2+
global using DotNet.Testcontainers.Commons;
3+
global using Xunit;

0 commit comments

Comments
 (0)