Skip to content

Commit 14f9ad9

Browse files
committed
chore: Remove Sonar findings
1 parent 9b83bde commit 14f9ad9

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

src/Testcontainers/Builders/BuildConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class BuildConfiguration
1616
/// <returns>Changed configuration object. If there is no change, the previous configuration object.</returns>
1717
public static T Combine<T>(T oldValue, T newValue)
1818
{
19-
return newValue == null ? oldValue : newValue;
19+
return Equals(default(T), newValue) ? oldValue : newValue;
2020
}
2121

2222
/// <summary>

src/Testcontainers/Guard.Argument.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ArgumentInfo(TType value, string name)
5656
/// <returns>True if the argument has a value; otherwise, false.</returns>
5757
public bool HasValue()
5858
{
59-
return Value != null;
59+
return !Equals(default(TType), Value);
6060
}
6161
}
6262
}

src/Testcontainers/Images/DockerImage.cs

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public sealed class DockerImage : IImage
1414

1515
private static readonly char[] TrimChars = { ' ', ':', '/' };
1616

17+
private static readonly char[] HostnameIdentifierChars = { '.', ':' };
18+
1719
private readonly string _hubImageNamePrefix;
1820

1921
private readonly Lazy<string> _lazyFullName;
@@ -86,14 +88,7 @@ public DockerImage(
8688
.First()
8789
.Split('/')[0];
8890

89-
if (firstSegmentOfRepository.IndexOfAny(new[] { '.', ':' }) >= 0)
90-
{
91-
return firstSegmentOfRepository;
92-
}
93-
else
94-
{
95-
return null;
96-
}
91+
return firstSegmentOfRepository.IndexOfAny(HostnameIdentifierChars) >= 0 ? firstSegmentOfRepository : null;
9792
});
9893
}
9994

src/Testcontainers/Images/DockerfileArchive.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DockerfileArchive(DirectoryInfo dockerfileDirectory, FileInfo dockerfile,
5555
throw new ArgumentException($"Directory '{dockerfileDirectory.FullName}' does not exist.");
5656
}
5757

58-
if (!dockerfileDirectory.GetFiles(dockerfile.ToString(), SearchOption.TopDirectoryOnly).Any())
58+
if (dockerfileDirectory.GetFiles(dockerfile.ToString(), SearchOption.TopDirectoryOnly).Length == 0)
5959
{
6060
throw new ArgumentException($"{dockerfile} does not exist in '{dockerfileDirectory.FullName}'.");
6161
}

tests/Testcontainers.Commons/CommonImages.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace DotNet.Testcontainers.Commons;
33
[PublicAPI]
44
public static class CommonImages
55
{
6-
public static readonly IImage Ryuk = new DockerImage("testcontainers/ryuk:0.5.1");
6+
public static readonly IImage Ryuk = new DockerImage("testcontainers/ryuk:0.6.0");
77

88
public static readonly IImage Alpine = new DockerImage("alpine:3.17");
99

tests/Testcontainers.Databases.Tests/DatabasesContainerTest.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public void ShouldNotImplementIDatabaseContainer(Type type)
1616
Assert.False(type.IsAssignableTo(typeof(IDatabaseContainer)), $"The type '{type.Name}' does implement the database interface.");
1717
}
1818

19-
public static IEnumerable<object[]> GetContainerImplementations(bool expectDataProvider)
19+
public static TheoryData<Type> GetContainerImplementations(bool expectDataProvider)
2020
{
21+
var theoryData = new TheoryData<Type>();
22+
2123
var testAssemblies = Directory.GetFiles(".", "Testcontainers.*.Tests.dll", SearchOption.TopDirectoryOnly)
2224
.Select(Path.GetFullPath)
2325
.Select(Assembly.LoadFrom)
@@ -41,14 +43,16 @@ public static IEnumerable<object[]> GetContainerImplementations(bool expectDataP
4143

4244
if (expectDataProvider && hasDataProvider)
4345
{
44-
yield return new object[] { containerType };
46+
theoryData.Add(containerType);
4547
}
4648

4749
if (!expectDataProvider && !hasDataProvider)
4850
{
49-
yield return new object[] { containerType };
51+
theoryData.Add(containerType);
5052
}
5153
}
5254
}
55+
56+
return theoryData;
5357
}
5458
}

tests/Testcontainers.Tests/Unit/Configurations/DockerImageNameSubstitutionTest.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace DotNet.Testcontainers.Tests.Unit
22
{
33
using System;
4-
using System.Collections.Generic;
54
using DotNet.Testcontainers.Builders;
65
using DotNet.Testcontainers.Configurations;
76
using DotNet.Testcontainers.Containers;
@@ -14,20 +13,20 @@ public static class DockerImageNameSubstitutionTest
1413
[Collection(nameof(DockerImageNameSubstitutionTest))]
1514
public sealed class HubImageNamePrefixIsSet : IDisposable
1615
{
17-
public static IEnumerable<object[]> Substitutions { get; }
18-
= new[]
16+
public static TheoryData<string, string, string> Substitutions { get; }
17+
= new TheoryData<string, string, string>
1918
{
20-
new[] { "my.proxy.com", "bar", "my.proxy.com/bar:latest" },
21-
new[] { "my.proxy.com", "bar:latest", "my.proxy.com/bar:latest" },
22-
new[] { "my.proxy.com", "bar:1.0.0", "my.proxy.com/bar:1.0.0" },
23-
new[] { "my.proxy.com/my-path", "bar:1.0.0", "my.proxy.com/my-path/bar:1.0.0" },
24-
new[] { "my.proxy.com:443", "bar:1.0.0", "my.proxy.com:443/bar:1.0.0" },
25-
new[] { "my.proxy.com", "foo/bar:1.0.0", "my.proxy.com/foo/bar:1.0.0" },
26-
new[] { "my.proxy.com/my-path", "foo/bar:1.0.0", "my.proxy.com/my-path/foo/bar:1.0.0" },
27-
new[] { "my.proxy.com:443", "foo/bar:1.0.0", "my.proxy.com:443/foo/bar:1.0.0" },
28-
new[] { "my.proxy.com:443/my-path", "foo/bar:1.0.0", "my.proxy.com:443/my-path/foo/bar:1.0.0" },
29-
new[] { "my.proxy.com", "myregistry.azurecr.io/foo/bar:1.0.0", "myregistry.azurecr.io/foo/bar:1.0.0" },
30-
new[] { "my.proxy.com", "myregistry.azurecr.io:443/foo/bar:1.0.0", "myregistry.azurecr.io:443/foo/bar:1.0.0" },
19+
{ "my.proxy.com", "bar", "my.proxy.com/bar:latest" },
20+
{ "my.proxy.com", "bar:latest", "my.proxy.com/bar:latest" },
21+
{ "my.proxy.com", "bar:1.0.0", "my.proxy.com/bar:1.0.0" },
22+
{ "my.proxy.com/my-path", "bar:1.0.0", "my.proxy.com/my-path/bar:1.0.0" },
23+
{ "my.proxy.com:443", "bar:1.0.0", "my.proxy.com:443/bar:1.0.0" },
24+
{ "my.proxy.com", "foo/bar:1.0.0", "my.proxy.com/foo/bar:1.0.0" },
25+
{ "my.proxy.com/my-path", "foo/bar:1.0.0", "my.proxy.com/my-path/foo/bar:1.0.0" },
26+
{ "my.proxy.com:443", "foo/bar:1.0.0", "my.proxy.com:443/foo/bar:1.0.0" },
27+
{ "my.proxy.com:443/my-path", "foo/bar:1.0.0", "my.proxy.com:443/my-path/foo/bar:1.0.0" },
28+
{ "my.proxy.com", "myregistry.azurecr.io/foo/bar:1.0.0", "myregistry.azurecr.io/foo/bar:1.0.0" },
29+
{ "my.proxy.com", "myregistry.azurecr.io:443/foo/bar:1.0.0", "myregistry.azurecr.io:443/foo/bar:1.0.0" },
3130
};
3231

3332
[Theory]

0 commit comments

Comments
 (0)