Skip to content
Merged
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: 0 additions & 1 deletion Testcontainers.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<Project Path="src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj"/>
<Project Path="src/Testcontainers.Elasticsearch/Testcontainers.Elasticsearch.csproj"/>
<Project Path="src/Testcontainers.EventHubs/Testcontainers.EventHubs.csproj"/>
<Project Path="src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj"/>
<Project Path="src/Testcontainers.FakeGcsServer/Testcontainers.FakeGcsServer.csproj"/>
<Project Path="src/Testcontainers.FirebirdSql/Testcontainers.FirebirdSql.csproj"/>
<Project Path="src/Testcontainers.Firestore/Testcontainers.Firestore.csproj"/>
Expand Down
52 changes: 46 additions & 6 deletions src/Testcontainers/Builders/BuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,29 @@ public static IEnumerable<T> Combine<T>(
return Array.Empty<T>();
}

if (newValue == null || oldValue == null)
if (newValue == null)
{
return newValue ?? oldValue;
return oldValue;
}

if (oldValue == null)
{
return newValue;
}

if (newValue is ICollection<T> collection && collection.Count == 0)
{
return oldValue;
}

if (oldValue is not ICollection<T>)
{
oldValue = oldValue.ToArray();
}

if (newValue is not ICollection<T>)
{
newValue = newValue.ToArray();
}

return oldValue.Concat(newValue).ToArray();
Expand All @@ -68,9 +88,19 @@ public static IReadOnlyList<T> Combine<T>(
return Array.Empty<T>();
}

if (newValue == null || oldValue == null)
if (newValue == null)
{
return newValue ?? oldValue;
return oldValue;
}

if (oldValue == null)
{
return newValue;
}

if (newValue.Count == 0)
{
return oldValue;
}

return oldValue.Concat(newValue).ToArray();
Expand Down Expand Up @@ -128,9 +158,19 @@ public static IReadOnlyDictionary<TKey, TValue> Combine<TKey, TValue>(
return new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>());
}

if (newValue == null || oldValue == null)
if (newValue == null)
{
return newValue ?? oldValue;
return oldValue;
}

if (oldValue == null)
{
return newValue;
}

if (newValue.Count == 0)
{
return oldValue;
}

var result = new Dictionary<TKey, TValue>(oldValue.Count + newValue.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ContainerConfiguration : ResourceConfiguration<CreateContainerParam
/// <param name="outputConsumer">The output consumer.</param>
/// <param name="waitStrategies">The wait strategies.</param>
/// <param name="startupCallback">The startup callback.</param>
/// <param name="connectionStringProvider">The connection string provider.</param>
/// <param name="autoRemove">A value indicating whether Docker removes the container after it exits or not.</param>
/// <param name="privileged">A value indicating whether the privileged flag is set or not.</param>
public ContainerConfiguration(
Expand Down
2 changes: 1 addition & 1 deletion tests/Testcontainers.Commons/DockerfileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Dictionary<string, string> Parse()
var stages = fromMatches
.Select(match => new
{
Stage = match.Value.Split(separator, options).Skip(1).DefaultIfEmpty(string.Empty).First(),
Stage = match.Value.Split(separator, options).Skip(1).FirstOrDefault(string.Empty),
Image = match.Groups[imageGroup].Value,
})
.ToDictionary(
Expand Down
4 changes: 2 additions & 2 deletions tests/Testcontainers.Commons/TestSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace DotNet.Testcontainers.Commons;
[PublicAPI]
public static class TestSession
{
private static readonly ConcurrentDictionary<string, Dictionary<string, string>> Cache = new ConcurrentDictionary<string, Dictionary<string, string>>();
private static readonly ConcurrentDictionary<string, Dictionary<string, string>> Stages = new ConcurrentDictionary<string, Dictionary<string, string>>();

public static readonly string TempDirectoryPath = Path.Combine(Path.GetTempPath(), "testcontainers-tests", Guid.NewGuid().ToString("D"));

Expand All @@ -16,7 +16,7 @@ public static string GetImageFromDockerfile(string relativeFilePath = "Dockerfil
{
var absoluteFilePath = Path.GetFullPath(relativeFilePath);

var stages = Cache.GetOrAdd(absoluteFilePath, filePath => new DockerfileParser(filePath).Parse());
var stages = Stages.GetOrAdd(absoluteFilePath, filePath => new DockerfileParser(filePath).Parse());

if (stages.TryGetValue(stage, out var image))
{
Expand Down