diff --git a/.gitattributes b/.gitattributes index 3149ef92c..948006214 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,6 +12,7 @@ *.crt filter=lfs diff=lfs merge=lfs -text *.ico filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text +*.snk filter=lfs diff=lfs merge=lfs -text # Setting up Netlify with Git LFS is cumbersome docs/*.ico !filter=lfs !diff=lfs !merge=lfs -text diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index d7cad9dc3..ccac73517 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,6 +25,8 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 + with: + lfs: true - name: Initialize CodeQL uses: github/codeql-action/init@v2 diff --git a/Directory.Build.props b/Directory.Build.props index 941d79ca0..2b2c6d1dd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), Testcontainers.sln))/ + $([MSBuild]::GetDirectoryNameOfFileAbove('$(MSBuildProjectDirectory)', 'Testcontainers.sln'))/ $(AssemblyName) @@ -23,13 +23,17 @@ git https://github.com/testcontainers/testcontainers-dotnet + + $(SolutionDir)src/strongname.snk + true + + + CS0618,CS1591,SA0001,SA1600,SA1633,SA1649 + true true - - CA1716,CS1591,SA0001,SA1402,SA1600,SA1633,SA1649,CS0618 - @@ -38,7 +42,7 @@ - <_Parameter1>Testcontainers.Tests + <_Parameter1>Testcontainers.Tests, PublicKey=$([System.IO.File]::ReadAllText($(SolutionDir)src/strongname.pub)) diff --git a/Packages.props b/Packages.props index 0dfe8a94e..58d6afd73 100644 --- a/Packages.props +++ b/Packages.props @@ -5,8 +5,8 @@ - - + + diff --git a/Testcontainers.sln b/Testcontainers.sln index 38d5d6312..fa4f6e62d 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redis", "src EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda", "src\Testcontainers.Redpanda\Testcontainers.Redpanda.csproj", "{45D6F69C-4D87-4130-AA90-0DB2F7460DAE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testcontainers\Testcontainers.csproj", "{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}" @@ -99,12 +101,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Redpanda.Tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ResourceReaper.Tests", "tests\Testcontainers.ResourceReaper.Tests\Testcontainers.ResourceReaper.Tests.csproj", "{9E8E6AA5-65D1-498F-BEAB-BA34723A0050}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge", "src\Testcontainers.SqlEdge\Testcontainers.SqlEdge.csproj", "{C95A3B2F-2B28-49A7-8806-731C158BBC21}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.SqlEdge.Tests", "tests\Testcontainers.SqlEdge.Tests\Testcontainers.SqlEdge.Tests.csproj", "{1A1983E6-5297-435F-B467-E8E1F11277D6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -190,6 +190,10 @@ Global {45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {45D6F69C-4D87-4130-AA90-0DB2F7460DAE}.Release|Any CPU.Build.0 = Release|Any CPU + {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU {EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Debug|Any CPU.Build.0 = Debug|Any CPU {EC76857B-A3B8-4B7A-A1B0-8D867A4D1733}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -286,18 +290,14 @@ Global {9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Debug|Any CPU.Build.0 = Debug|Any CPU {9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.ActiveCfg = Release|Any CPU {9E8E6AA5-65D1-498F-BEAB-BA34723A0050}.Release|Any CPU.Build.0 = Release|Any CPU - {27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU - {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C95A3B2F-2B28-49A7-8806-731C158BBC21}.Release|Any CPU.Build.0 = Release|Any CPU {1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1A1983E6-5297-435F-B467-E8E1F11277D6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.ActiveCfg = Release|Any CPU {1A1983E6-5297-435F-B467-E8E1F11277D6}.Release|Any CPU.Build.0 = Release|Any CPU + {27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -319,6 +319,7 @@ Global {F6394475-D6F1-46E2-81BF-4BA78A40B878} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {BFDA179A-40EB-4CEB-B8E9-0DF32C65E2C5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {45D6F69C-4D87-4130-AA90-0DB2F7460DAE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} @@ -343,8 +344,7 @@ Global {31EE94A0-E721-4073-B6F1-DD912D004DEF} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {867BD04E-4670-4FBA-98D5-9F83220E6DFB} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} - {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} - {C95A3B2F-2B28-49A7-8806-731C158BBC21} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/build.cake b/build.cake index dcc88c0c9..0394ec70e 100644 --- a/build.cake +++ b/build.cake @@ -67,7 +67,6 @@ Task("Build") Verbosity = param.Verbosity, NoRestore = true, ArgumentCustomization = args => args - .Append($"/p:TreatWarningsAsErrors={param.IsReleaseBuild.ToString()}") }); }); diff --git a/src/Testcontainers.MongoDb/MongoDbBuilder.cs b/src/Testcontainers.MongoDb/MongoDbBuilder.cs index e5b299948..fe3f7b57c 100644 --- a/src/Testcontainers.MongoDb/MongoDbBuilder.cs +++ b/src/Testcontainers.MongoDb/MongoDbBuilder.cs @@ -60,9 +60,7 @@ public MongoDbBuilder WithPassword(string password) public override MongoDbContainer Build() { Validate(); - - var mongoDbBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil(DockerResourceConfiguration))); - return new MongoDbContainer(mongoDbBuilder.DockerResourceConfiguration, TestcontainersSettings.Logger); + return new MongoDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); } /// @@ -72,7 +70,8 @@ protected override MongoDbBuilder Init() .WithImage(MongoDbImage) .WithPortBinding(MongoDbPort, true) .WithUsername(DefaultUsername) - .WithPassword(DefaultPassword); + .WithPassword(DefaultPassword) + .WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil())); } /// @@ -110,25 +109,18 @@ protected override MongoDbBuilder Merge(MongoDbConfiguration oldValue, MongoDbCo /// private sealed class WaitUntil : IWaitUntil { - private readonly IList _mongoDbShellCommand; - - /// - /// Initializes a new instance of the class. - /// - /// The container configuration. - public WaitUntil(MongoDbConfiguration configuration) - { - const string js = "db.runCommand({hello:1}).isWritablePrimary"; - _mongoDbShellCommand = new MongoDbShellCommand(js, configuration.Username, configuration.Password); - } + private static readonly string[] LineEndings = { "\r\n", "\n" }; /// public async Task UntilAsync(IContainer container) { - var execResult = await container.ExecAsync(_mongoDbShellCommand) + var (stdout, stderr) = await container.GetLogs(timestampsEnabled: false) .ConfigureAwait(false); - return 0L.Equals(execResult.ExitCode) && "true\n".Equals(execResult.Stdout, StringComparison.OrdinalIgnoreCase); + return 2.Equals(Array.Empty() + .Concat(stdout.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries)) + .Concat(stderr.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries)) + .Count(line => line.Contains("Waiting for connections"))); } } } \ No newline at end of file diff --git a/src/Testcontainers.MongoDb/MongoDbContainer.cs b/src/Testcontainers.MongoDb/MongoDbContainer.cs index 5271abba3..12aa06810 100644 --- a/src/Testcontainers.MongoDb/MongoDbContainer.cs +++ b/src/Testcontainers.MongoDb/MongoDbContainer.cs @@ -43,7 +43,18 @@ public async Task ExecScriptAsync(string scriptContent, Cancellation await CopyFileAsync(scriptFilePath, Encoding.Default.GetBytes(scriptContent), 493, 0, 0, ct) .ConfigureAwait(false); - return await ExecAsync(new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password), ct) + + var mongoShellCommand = new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password); + + Logger.LogInformation(string.Format("{0}: {1}", Id, string.Join(" ", mongoShellCommand))); + + var result = await ExecAsync(mongoShellCommand, ct) .ConfigureAwait(false); + + Logger.LogInformation(string.Format("{0}: {1}", "ExitCode", result.ExitCode)); + Logger.LogInformation(string.Format("{0}: {1}", "Stdout", result.Stdout)); + Logger.LogInformation(string.Format("{0}: {1}", "Stderr", result.Stderr)); + + return result; } } \ No newline at end of file diff --git a/src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs b/src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs index 3a0a560f7..e80325ef8 100644 --- a/src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs +++ b/src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs @@ -1,4 +1,5 @@ -#pragma warning disable SA1403 +#pragma warning disable SA1402 +#pragma warning disable SA1403 namespace DotNet.Testcontainers { @@ -98,4 +99,5 @@ public sealed class TestcontainersBuilder : ContainerBuilder [PublicAPI] - public sealed partial class DockerImage : IImage + public sealed class DockerImage : IImage { private static readonly Func GetDockerImage = MatchImage.Match; diff --git a/src/strongname.pub b/src/strongname.pub new file mode 100644 index 000000000..3435a0b14 --- /dev/null +++ b/src/strongname.pub @@ -0,0 +1 @@ +0024000004800000940000000602000000240000525341310004000001000100d11d30732581cf3e164cf872af326ceeeee2ff5ed15e68a9dad4c3ee5a60d9f6d094a50f82347147200cfe4710562800bb40296b160cab40def36769087e7d0938bd109df4cc015659f014430c325ce25259407402f1efd6ab33dec7a0d073e00e09f205f447a127558d862a15fe20aed1c607b615536c1ac2f92870e90b87c4 \ No newline at end of file diff --git a/src/strongname.snk b/src/strongname.snk new file mode 100644 index 000000000..d8c37dabc --- /dev/null +++ b/src/strongname.snk @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f38c749ff7790241c728a936bb535e427d8a47fbc63a4672a1758e06374ca069 +size 596 diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props new file mode 100644 index 000000000..fa3e83f97 --- /dev/null +++ b/tests/Directory.Build.props @@ -0,0 +1,7 @@ + + + + + false + + diff --git a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj index 94a68b191..fb12c938b 100644 --- a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj +++ b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj @@ -7,6 +7,9 @@ Debug;Release DotNet.Testcontainers.Commons + + true + diff --git a/tests/Testcontainers.Tests/Testcontainers.Tests.csproj b/tests/Testcontainers.Tests/Testcontainers.Tests.csproj index 224cd0c16..0d285dc78 100644 --- a/tests/Testcontainers.Tests/Testcontainers.Tests.csproj +++ b/tests/Testcontainers.Tests/Testcontainers.Tests.csproj @@ -7,6 +7,9 @@ Debug;Release DotNet.Testcontainers.Tests + + true +