Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Seq Module #1276

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
{ name: "Testcontainers.RavenDb", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Redis", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Redpanda", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Seq", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.WebDriver", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Xunit", runs-on: "ubuntu-22.04" }
]
Expand Down
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="Docker.DotNet.Enhanced" Version="3.126.0"/>
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0"/>
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="1.1.1"/>
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2"/>
<PackageVersion Include="SharpZipLib" Version="1.4.2"/>
<PackageVersion Include="SSH.NET" Version="2024.1.0"/>
Expand All @@ -23,6 +24,8 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="xunit.v3.extensibility.core" Version="0.2.0-pre.69"/>
<PackageVersion Include="xunit" Version="2.9.2"/>
<PackageVersion Include="Seq.Api" Version="2024.3.0"/>
<PackageVersion Include="Seq.Extensions.Logging" Version="8.0.0"/>
<!-- Third-party client dependencies to connect and interact with the containers: -->
<PackageVersion Include="Apache.NMS.ActiveMQ" Version="2.1.0"/>
<PackageVersion Include="ArangoDBNetStandard" Version="2.0.1"/>
Expand Down
23 changes: 20 additions & 3 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Xunit.Tests", "tests\Testcontainers.Xunit.Tests\Testcontainers.Xunit.Tests.csproj", "{E901DF14-6F05-4FC2-825A-3055FAD33561}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq", "..\testcontainers-dotnet\src\Testcontainers.Seq\Testcontainers.Seq.csproj", "{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq.Tests", "..\testcontainers-dotnet\tests\Testcontainers.Seq.Tests\Testcontainers.Seq.Tests.csproj", "{6FF86CD0-3801-ADE4-A59B-271AC8B2390C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -586,6 +587,17 @@ Global
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E901DF14-6F05-4FC2-825A-3055FAD33561}.Release|Any CPU.Build.0 = Release|Any CPU
{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6}.Release|Any CPU.Build.0 = Release|Any CPU
{6FF86CD0-3801-ADE4-A59B-271AC8B2390C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FF86CD0-3801-ADE4-A59B-271AC8B2390C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FF86CD0-3801-ADE4-A59B-271AC8B2390C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FF86CD0-3801-ADE4-A59B-271AC8B2390C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -682,5 +694,10 @@ Global
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E901DF14-6F05-4FC2-825A-3055FAD33561} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{F148CB77-9438-9DCF-CA37-75F7BCD5FEF6} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{6FF86CD0-3801-ADE4-A59B-271AC8B2390C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5EC93352-CD4F-4CB4-84D3-B822DB932443}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/Testcontainers.Seq/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
72 changes: 72 additions & 0 deletions src/Testcontainers.Seq/SeqBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace Testcontainers.Seq;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class SeqBuilder : ContainerBuilder<SeqBuilder, SeqContainer, SeqConfiguration>
{
public const string SeqImage = "datalust/seq:2024.2.11456";
montanehamilton marked this conversation as resolved.
Show resolved Hide resolved

public const ushort SeqApiPort = 80;
public const ushort SeqIngestionPort = 5341;

/// <inheritdoc />
protected override SeqConfiguration DockerResourceConfiguration { get; }

/// <summary>
/// Initializes a new instance of the <see cref="SeqBuilder" /> class.
/// </summary>
public SeqBuilder()
: this(new SeqConfiguration())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}

/// <summary>
/// Initializes a new instance of the <see cref="SeqBuilder" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
private SeqBuilder(SeqConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
DockerResourceConfiguration = resourceConfiguration;
}

/// <inheritdoc />
public override SeqContainer Build()
{
Validate();
return new SeqContainer(DockerResourceConfiguration);
}
/// <inheritdoc />
protected override SeqBuilder Init()
{
return base.Init()
.WithImage(SeqImage)
.WithPortBinding(SeqApiPort, true)
.WithPortBinding(SeqIngestionPort, true)
.WithEnvironment(new Dictionary<string, string>
{
{"ACCEPT_EULA", "Y" }
})
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPath("/health").ForPort(SeqApiPort)));
}

/// <inheritdoc />
protected override SeqBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override SeqBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override SeqBuilder Merge(SeqConfiguration oldValue, SeqConfiguration newValue)
{
return new SeqBuilder(new SeqConfiguration(oldValue, newValue));
}
}
56 changes: 56 additions & 0 deletions src/Testcontainers.Seq/SeqConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Testcontainers.Seq;

/// <inheritdoc cref="ContainerConfiguration" />
[PublicAPI]
public sealed class SeqConfiguration : ContainerConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
/// </summary>
/// <param name="config">The Orion.TestContainers.Seq config.</param>
public SeqConfiguration(object config = null)
{
// Sets the custom builder methods property values.
}

/// <summary>
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public SeqConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
: base(resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public SeqConfiguration(IContainerConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public SeqConfiguration(SeqConfiguration resourceConfiguration)
: this(new SeqConfiguration(), resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="SeqConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public SeqConfiguration(SeqConfiguration oldValue, SeqConfiguration newValue)
: base(oldValue, newValue)
{
// Create an updated immutable copy of the module configuration.
}
}
22 changes: 22 additions & 0 deletions src/Testcontainers.Seq/SeqContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Testcontainers.Seq;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class SeqContainer : DockerContainer
{
/// <summary>
/// Initializes a new instance of the <see cref="SeqContainer" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
public SeqContainer(SeqConfiguration configuration)
: base(configuration)
{
}

public string GetServerApiUrl()
{
return new UriBuilder("http", Hostname, GetMappedPublicPort(SeqBuilder.SeqApiPort)).Uri.ToString();
}
}
12 changes: 12 additions & 0 deletions src/Testcontainers.Seq/Testcontainers.Seq.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/Testcontainers.Seq/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global using System.Collections.Generic;
global using Docker.DotNet.Models;
global using DotNet.Testcontainers.Builders;
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,59 @@
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers.*.Tests/Testcontainers.*.Tests.csproj"/>
<ProjectReference Remove="Testcontainers.Databases.Tests.csproj"/>
<ProjectReference Include="..\..\..\testcontainers-dotnet\src\Testcontainers.Seq\Testcontainers.Seq.csproj" />
<ProjectReference Include="..\Testcontainers.ActiveMq.Tests\Testcontainers.ActiveMq.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.ArangoDb.Tests\Testcontainers.ArangoDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Azurite.Tests\Testcontainers.Azurite.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.BigQuery.Tests\Testcontainers.BigQuery.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Bigtable.Tests\Testcontainers.Bigtable.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.ClickHouse.Tests\Testcontainers.ClickHouse.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.CockroachDb.Tests\Testcontainers.CockroachDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Consul.Tests\Testcontainers.Consul.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.CosmosDb.Tests\Testcontainers.CosmosDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Couchbase.Tests\Testcontainers.Couchbase.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.CouchDb.Tests\Testcontainers.CouchDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.DynamoDb.Tests\Testcontainers.DynamoDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Elasticsearch.Tests\Testcontainers.Elasticsearch.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.FakeGcsServer.Tests\Testcontainers.FakeGcsServer.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.FirebirdSql.Tests\Testcontainers.FirebirdSql.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Firestore.Tests\Testcontainers.Firestore.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.InfluxDb.Tests\Testcontainers.InfluxDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.JanusGraph.Tests\Testcontainers.JanusGraph.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.K3s.Tests\Testcontainers.K3s.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Kafka.Tests\Testcontainers.Kafka.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Keycloak.Tests\Testcontainers.Keycloak.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Kusto.Tests\Testcontainers.Kusto.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.LocalStack.Tests\Testcontainers.LocalStack.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.MariaDb.Tests\Testcontainers.MariaDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Milvus.Tests\Testcontainers.Milvus.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Minio.Tests\Testcontainers.Minio.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.MongoDb.Tests\Testcontainers.MongoDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.MsSql.Tests\Testcontainers.MsSql.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.MySql.Tests\Testcontainers.MySql.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Nats.Tests\Testcontainers.Nats.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Neo4j.Tests\Testcontainers.Neo4j.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Oracle.Tests\Testcontainers.Oracle.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Papercut.Tests\Testcontainers.Papercut.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Platform.Linux.Tests\Testcontainers.Platform.Linux.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Platform.Windows.Tests\Testcontainers.Platform.Windows.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.PostgreSql.Tests\Testcontainers.PostgreSql.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.PubSub.Tests\Testcontainers.PubSub.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Pulsar.Tests\Testcontainers.Pulsar.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.RabbitMq.Tests\Testcontainers.RabbitMq.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.RavenDb.Tests\Testcontainers.RavenDb.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Redis.Tests\Testcontainers.Redis.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Redpanda.Tests\Testcontainers.Redpanda.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.ResourceReaper.Tests\Testcontainers.ResourceReaper.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj" />
<ProjectReference Include="..\Testcontainers.Xunit.Tests\Testcontainers.Xunit.Tests.csproj" />
<ProjectReference Remove="Testcontainers.Databases.Tests.csproj" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions tests/Testcontainers.Seq.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
38 changes: 38 additions & 0 deletions tests/Testcontainers.Seq.Tests/SeqContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Extensions.Logging;
using Seq.Api;
using System;
using System.Linq;

namespace Testcontainers.Seq;

public sealed class SeqContainerTest : IAsyncLifetime
{
private readonly SeqContainer _seqContainer = new SeqBuilder().Build();

public Task InitializeAsync()
{
return _seqContainer.StartAsync();
}

public Task DisposeAsync()
{
return _seqContainer.DisposeAsync().AsTask();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task CanLog()
{
var currentSeqApiPort = _seqContainer.GetMappedPublicPort(80);
var currentSeqHostname = _seqContainer.Hostname;

ILoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddSeq(_seqContainer.GetServerApiUrl());
var testLogger = loggerFactory.CreateLogger("testlogger");
testLogger.LogInformation("TRY THIS");

var seqConnection = new SeqConnection(_seqContainer.GetServerApiUrl());
var eventList = await seqConnection.Events.ListAsync(fromDateUtc: DateTime.Now.AddMinutes(-1));
Assert.Contains(eventList, e => e.MessageTemplateTokens.Last().Text == "TRY THIS");
}
}
26 changes: 26 additions & 0 deletions tests/Testcontainers.Seq.Tests/Testcontainers.Seq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Seq.Api" />
<PackageReference Include="Seq.Extensions.Logging" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Testcontainers.Seq\Testcontainers.Seq.csproj" />
<ProjectReference Include="..\Testcontainers.Commons\Testcontainers.Commons.csproj" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions tests/Testcontainers.Seq.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using Xunit;