diff --git a/src/Testcontainers/Builders/BuildConfiguration.cs b/src/Testcontainers/Builders/BuildConfiguration.cs index 408fad9b3..b96a71c48 100644 --- a/src/Testcontainers/Builders/BuildConfiguration.cs +++ b/src/Testcontainers/Builders/BuildConfiguration.cs @@ -16,7 +16,7 @@ public static class BuildConfiguration /// Changed configuration object. If there is no change, the previous configuration object. public static T Combine(T oldValue, T newValue) { - return newValue == null ? oldValue : newValue; + return Equals(default(T), newValue) ? oldValue : newValue; } /// diff --git a/src/Testcontainers/Guard.Argument.cs b/src/Testcontainers/Guard.Argument.cs index 8059f3ab5..d0189c5e5 100644 --- a/src/Testcontainers/Guard.Argument.cs +++ b/src/Testcontainers/Guard.Argument.cs @@ -56,7 +56,7 @@ public ArgumentInfo(TType value, string name) /// True if the argument has a value; otherwise, false. public bool HasValue() { - return Value != null; + return !Equals(default(TType), Value); } } } diff --git a/src/Testcontainers/Images/DockerImage.cs b/src/Testcontainers/Images/DockerImage.cs index 671211af2..b37ae0c4a 100644 --- a/src/Testcontainers/Images/DockerImage.cs +++ b/src/Testcontainers/Images/DockerImage.cs @@ -14,6 +14,8 @@ public sealed class DockerImage : IImage private static readonly char[] TrimChars = { ' ', ':', '/' }; + private static readonly char[] HostnameIdentifierChars = { '.', ':' }; + private readonly string _hubImageNamePrefix; private readonly Lazy _lazyFullName; @@ -86,14 +88,7 @@ public DockerImage( .First() .Split('/')[0]; - if (firstSegmentOfRepository.IndexOfAny(new[] { '.', ':' }) >= 0) - { - return firstSegmentOfRepository; - } - else - { - return null; - } + return firstSegmentOfRepository.IndexOfAny(HostnameIdentifierChars) >= 0 ? firstSegmentOfRepository : null; }); } diff --git a/src/Testcontainers/Images/DockerfileArchive.cs b/src/Testcontainers/Images/DockerfileArchive.cs index c752ca050..c543e17f8 100644 --- a/src/Testcontainers/Images/DockerfileArchive.cs +++ b/src/Testcontainers/Images/DockerfileArchive.cs @@ -55,7 +55,7 @@ public DockerfileArchive(DirectoryInfo dockerfileDirectory, FileInfo dockerfile, throw new ArgumentException($"Directory '{dockerfileDirectory.FullName}' does not exist."); } - if (!dockerfileDirectory.GetFiles(dockerfile.ToString(), SearchOption.TopDirectoryOnly).Any()) + if (dockerfileDirectory.GetFiles(dockerfile.ToString(), SearchOption.TopDirectoryOnly).Length == 0) { throw new ArgumentException($"{dockerfile} does not exist in '{dockerfileDirectory.FullName}'."); } diff --git a/tests/Testcontainers.Commons/CommonImages.cs b/tests/Testcontainers.Commons/CommonImages.cs index 4e0416655..84e1090e2 100644 --- a/tests/Testcontainers.Commons/CommonImages.cs +++ b/tests/Testcontainers.Commons/CommonImages.cs @@ -3,7 +3,7 @@ namespace DotNet.Testcontainers.Commons; [PublicAPI] public static class CommonImages { - public static readonly IImage Ryuk = new DockerImage("testcontainers/ryuk:0.5.1"); + public static readonly IImage Ryuk = new DockerImage("testcontainers/ryuk:0.6.0"); public static readonly IImage Alpine = new DockerImage("alpine:3.17"); diff --git a/tests/Testcontainers.Databases.Tests/DatabasesContainerTest.cs b/tests/Testcontainers.Databases.Tests/DatabasesContainerTest.cs index 694f7b5ec..5aff13fd4 100644 --- a/tests/Testcontainers.Databases.Tests/DatabasesContainerTest.cs +++ b/tests/Testcontainers.Databases.Tests/DatabasesContainerTest.cs @@ -16,8 +16,10 @@ public void ShouldNotImplementIDatabaseContainer(Type type) Assert.False(type.IsAssignableTo(typeof(IDatabaseContainer)), $"The type '{type.Name}' does implement the database interface."); } - public static IEnumerable GetContainerImplementations(bool expectDataProvider) + public static TheoryData GetContainerImplementations(bool expectDataProvider) { + var theoryData = new TheoryData(); + var testAssemblies = Directory.GetFiles(".", "Testcontainers.*.Tests.dll", SearchOption.TopDirectoryOnly) .Select(Path.GetFullPath) .Select(Assembly.LoadFrom) @@ -41,14 +43,16 @@ public static IEnumerable GetContainerImplementations(bool expectDataP if (expectDataProvider && hasDataProvider) { - yield return new object[] { containerType }; + theoryData.Add(containerType); } if (!expectDataProvider && !hasDataProvider) { - yield return new object[] { containerType }; + theoryData.Add(containerType); } } } + + return theoryData; } } \ No newline at end of file diff --git a/tests/Testcontainers.Tests/Unit/Configurations/DockerImageNameSubstitutionTest.cs b/tests/Testcontainers.Tests/Unit/Configurations/DockerImageNameSubstitutionTest.cs index 69ca5f76d..e316dfb55 100644 --- a/tests/Testcontainers.Tests/Unit/Configurations/DockerImageNameSubstitutionTest.cs +++ b/tests/Testcontainers.Tests/Unit/Configurations/DockerImageNameSubstitutionTest.cs @@ -1,7 +1,6 @@ namespace DotNet.Testcontainers.Tests.Unit { using System; - using System.Collections.Generic; using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Configurations; using DotNet.Testcontainers.Containers; @@ -14,20 +13,20 @@ public static class DockerImageNameSubstitutionTest [Collection(nameof(DockerImageNameSubstitutionTest))] public sealed class HubImageNamePrefixIsSet : IDisposable { - public static IEnumerable Substitutions { get; } - = new[] + public static TheoryData Substitutions { get; } + = new TheoryData { - new[] { "my.proxy.com", "bar", "my.proxy.com/bar:latest" }, - new[] { "my.proxy.com", "bar:latest", "my.proxy.com/bar:latest" }, - new[] { "my.proxy.com", "bar:1.0.0", "my.proxy.com/bar:1.0.0" }, - new[] { "my.proxy.com/my-path", "bar:1.0.0", "my.proxy.com/my-path/bar:1.0.0" }, - new[] { "my.proxy.com:443", "bar:1.0.0", "my.proxy.com:443/bar:1.0.0" }, - new[] { "my.proxy.com", "foo/bar:1.0.0", "my.proxy.com/foo/bar:1.0.0" }, - new[] { "my.proxy.com/my-path", "foo/bar:1.0.0", "my.proxy.com/my-path/foo/bar:1.0.0" }, - new[] { "my.proxy.com:443", "foo/bar:1.0.0", "my.proxy.com:443/foo/bar:1.0.0" }, - new[] { "my.proxy.com:443/my-path", "foo/bar:1.0.0", "my.proxy.com:443/my-path/foo/bar:1.0.0" }, - new[] { "my.proxy.com", "myregistry.azurecr.io/foo/bar:1.0.0", "myregistry.azurecr.io/foo/bar:1.0.0" }, - new[] { "my.proxy.com", "myregistry.azurecr.io:443/foo/bar:1.0.0", "myregistry.azurecr.io:443/foo/bar:1.0.0" }, + { "my.proxy.com", "bar", "my.proxy.com/bar:latest" }, + { "my.proxy.com", "bar:latest", "my.proxy.com/bar:latest" }, + { "my.proxy.com", "bar:1.0.0", "my.proxy.com/bar:1.0.0" }, + { "my.proxy.com/my-path", "bar:1.0.0", "my.proxy.com/my-path/bar:1.0.0" }, + { "my.proxy.com:443", "bar:1.0.0", "my.proxy.com:443/bar:1.0.0" }, + { "my.proxy.com", "foo/bar:1.0.0", "my.proxy.com/foo/bar:1.0.0" }, + { "my.proxy.com/my-path", "foo/bar:1.0.0", "my.proxy.com/my-path/foo/bar:1.0.0" }, + { "my.proxy.com:443", "foo/bar:1.0.0", "my.proxy.com:443/foo/bar:1.0.0" }, + { "my.proxy.com:443/my-path", "foo/bar:1.0.0", "my.proxy.com:443/my-path/foo/bar:1.0.0" }, + { "my.proxy.com", "myregistry.azurecr.io/foo/bar:1.0.0", "myregistry.azurecr.io/foo/bar:1.0.0" }, + { "my.proxy.com", "myregistry.azurecr.io:443/foo/bar:1.0.0", "myregistry.azurecr.io:443/foo/bar:1.0.0" }, }; [Theory]