Skip to content

Commit a4e439a

Browse files
fix: Avoid nullable enum Equals in Kafka vendor selection (#1830)
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
1 parent 90273a1 commit a4e439a

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎src/Testcontainers.Kafka/KafkaBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,6 @@ protected override KafkaBuilder Merge(KafkaConfiguration oldValue, KafkaConfigur
305305
/// <returns>The vendor configuration.</returns>
306306
private static IKafkaVendorConfiguration GetVendorConfiguration(KafkaConfiguration resourceConfiguration)
307307
{
308-
return VendorConfigurations.Single(v => v.Vendor.Equals(resourceConfiguration.Vendor) || v.IsImageFromVendor(resourceConfiguration.Image));
308+
return VendorConfigurations.Single(v => v.Vendor == resourceConfiguration.Vendor || v.IsImageFromVendor(resourceConfiguration.Image));
309309
}
310310
}

‎tests/Testcontainers.Kafka.Tests/KafkaBuilderTest.cs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ namespace Testcontainers.Kafka;
22

33
public sealed class KafkaBuilderTests
44
{
5+
[Theory]
6+
[InlineData("")]
7+
[InlineData("confluent-v8_2_4")]
8+
[InlineData("apache-v4_1_1")]
9+
[InlineData("apache-native-v4_4_0")]
10+
public void ImplicitVendorWithKnownImageDoesNotThrow(string stage)
11+
{
12+
var exception = Record.Exception(() => new KafkaBuilder(TestSession.GetImageFromDockerfile(stage: stage)).Build());
13+
Assert.Null(exception);
14+
}
15+
16+
[Theory]
17+
[InlineData(KafkaVendor.ApacheSoftwareFoundation)]
18+
[InlineData(KafkaVendor.Confluent)]
19+
public void ExplicitVendorWithCustomImageDoesNotThrow(KafkaVendor vendor)
20+
{
21+
var exception = Record.Exception(() => new KafkaBuilder("custom/kafka:1.0.0").WithVendor(vendor).Build());
22+
Assert.Null(exception);
23+
}
24+
525
[Fact]
626
public void KRaftWithConfluentPre7ThrowsArgumentException()
727
{
@@ -73,4 +93,4 @@ private static void ExpectArgEx(string message, Action testCode)
7393
var exception = Assert.Throws<ArgumentException>(testCode);
7494
Assert.StartsWith(message, exception.Message);
7595
}
76-
}
96+
}

0 commit comments

Comments
 (0)