diff --git a/Directory.Packages.props b/Directory.Packages.props index fbc55db0a..7248b0fa1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,7 +17,10 @@ + + + diff --git a/Testcontainers.sln b/Testcontainers.sln index 10cae3fc2..e500003dd 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -195,14 +195,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq", "src\Testcontainers.Seq\Testcontainers.Seq.csproj", "{7AC5C1F7-1469-4E5C-AF24-08F22012049E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Seq.Tests", "tests\Testcontainers.Seq.Tests\Testcontainers.Seq.Tests.csproj", "{14402644-8592-4A99-AD5F-F141DE0A4A8F}" +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 @@ -568,6 +569,17 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU + {7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AC5C1F7-1469-4E5C-AF24-08F22012049E}.Release|Any CPU.Build.0 = Release|Any CPU + {14402644-8592-4A99-AD5F-F141DE0A4A8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14402644-8592-4A99-AD5F-F141DE0A4A8F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14402644-8592-4A99-AD5F-F141DE0A4A8F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14402644-8592-4A99-AD5F-F141DE0A4A8F}.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} @@ -661,5 +673,7 @@ Global {9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {7AC5C1F7-1469-4E5C-AF24-08F22012049E} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {14402644-8592-4A99-AD5F-F141DE0A4A8F} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.Seq/.editorconfig b/src/Testcontainers.Seq/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/src/Testcontainers.Seq/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/src/Testcontainers.Seq/SeqBuilder.cs b/src/Testcontainers.Seq/SeqBuilder.cs new file mode 100644 index 000000000..e0648c85f --- /dev/null +++ b/src/Testcontainers.Seq/SeqBuilder.cs @@ -0,0 +1,72 @@ +namespace Testcontainers.Seq; + +/// +[PublicAPI] +public sealed class SeqBuilder : ContainerBuilder +{ + public const string SeqImage = "datalust/seq:2024.2.11456"; + + public const ushort SeqApiPort = 80; + public const ushort SeqIngestionPort = 5341; + + /// + protected override SeqConfiguration DockerResourceConfiguration { get; } + + /// + /// Initializes a new instance of the class. + /// + public SeqBuilder() + : this(new SeqConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private SeqBuilder(SeqConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + /// + public override SeqContainer Build() + { + Validate(); + return new SeqContainer(DockerResourceConfiguration); + } + /// + protected override SeqBuilder Init() + { + return base.Init() + .WithImage(SeqImage) + .WithPortBinding(SeqApiPort, true) + .WithPortBinding(SeqIngestionPort, true) + .WithEnvironment(new Dictionary + { + {"ACCEPT_EULA", "Y" } + }) + .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => + request.ForPath("/health").ForPort(SeqApiPort))); + } + + /// + protected override SeqBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration)); + } + + /// + protected override SeqBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new SeqConfiguration(resourceConfiguration)); + } + + /// + protected override SeqBuilder Merge(SeqConfiguration oldValue, SeqConfiguration newValue) + { + return new SeqBuilder(new SeqConfiguration(oldValue, newValue)); + } +} \ No newline at end of file diff --git a/src/Testcontainers.Seq/SeqConfiguration.cs b/src/Testcontainers.Seq/SeqConfiguration.cs new file mode 100644 index 000000000..3302aa1e9 --- /dev/null +++ b/src/Testcontainers.Seq/SeqConfiguration.cs @@ -0,0 +1,56 @@ +namespace Testcontainers.Seq; + +/// +[PublicAPI] +public sealed class SeqConfiguration : ContainerConfiguration +{ + /// + /// Initializes a new instance of the class. + /// + /// The Orion.TestContainers.Seq config. + public SeqConfiguration(object config = null) + { + // Sets the custom builder methods property values. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public SeqConfiguration(IResourceConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public SeqConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public SeqConfiguration(SeqConfiguration resourceConfiguration) + : this(new SeqConfiguration(), resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The old Docker resource configuration. + /// The new Docker resource configuration. + public SeqConfiguration(SeqConfiguration oldValue, SeqConfiguration newValue) + : base(oldValue, newValue) + { + // Create an updated immutable copy of the module configuration. + } +} \ No newline at end of file diff --git a/src/Testcontainers.Seq/SeqContainer.cs b/src/Testcontainers.Seq/SeqContainer.cs new file mode 100644 index 000000000..befc9850a --- /dev/null +++ b/src/Testcontainers.Seq/SeqContainer.cs @@ -0,0 +1,22 @@ +using System; + +namespace Testcontainers.Seq; + +/// +[PublicAPI] +public sealed class SeqContainer : DockerContainer +{ + /// + /// Initializes a new instance of the class. + /// + /// The container configuration. + public SeqContainer(SeqConfiguration configuration) + : base(configuration) + { + } + + public string GetServerApiUrl() + { + return new UriBuilder("http", Hostname, GetMappedPublicPort(SeqBuilder.SeqApiPort)).Uri.ToString(); + } +} \ No newline at end of file diff --git a/src/Testcontainers.Seq/Testcontainers.Seq.csproj b/src/Testcontainers.Seq/Testcontainers.Seq.csproj new file mode 100644 index 000000000..8b2ed72c6 --- /dev/null +++ b/src/Testcontainers.Seq/Testcontainers.Seq.csproj @@ -0,0 +1,12 @@ + + + net6.0;net8.0;netstandard2.0;netstandard2.1 + latest + + + + + + + + \ No newline at end of file diff --git a/src/Testcontainers.Seq/Usings.cs b/src/Testcontainers.Seq/Usings.cs new file mode 100644 index 000000000..080580c42 --- /dev/null +++ b/src/Testcontainers.Seq/Usings.cs @@ -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; diff --git a/tests/Testcontainers.Seq.Tests/.editorconfig b/tests/Testcontainers.Seq.Tests/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/tests/Testcontainers.Seq.Tests/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/tests/Testcontainers.Seq.Tests/SeqContainerTest.cs b/tests/Testcontainers.Seq.Tests/SeqContainerTest.cs new file mode 100644 index 000000000..ed30ff6e9 --- /dev/null +++ b/tests/Testcontainers.Seq.Tests/SeqContainerTest.cs @@ -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"); + } +} \ No newline at end of file diff --git a/tests/Testcontainers.Seq.Tests/Testcontainers.Seq.Tests.csproj b/tests/Testcontainers.Seq.Tests/Testcontainers.Seq.Tests.csproj new file mode 100644 index 000000000..4ea635b58 --- /dev/null +++ b/tests/Testcontainers.Seq.Tests/Testcontainers.Seq.Tests.csproj @@ -0,0 +1,26 @@ + + + net8.0 + false + false + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file diff --git a/tests/Testcontainers.Seq.Tests/Usings.cs b/tests/Testcontainers.Seq.Tests/Usings.cs new file mode 100644 index 000000000..346085388 --- /dev/null +++ b/tests/Testcontainers.Seq.Tests/Usings.cs @@ -0,0 +1,3 @@ +global using System.Threading.Tasks; +global using DotNet.Testcontainers.Commons; +global using Xunit; \ No newline at end of file