Skip to content

Commit d13cadf

Browse files
regmebuehler
andcommitted
fix: ToExpression(this IEnumerable<LabelSelector> selectors) extension method returns wrong result
Current inplementation of ```ToExpression(this IEnumerable<LabelSelector> selectors)``` extension method returns wrong result ``` EqualsSelector { Label = app, Values = System.String[] },NotEqualsSelector { Label = srv, Values = System.String[] } ``` it just serialize record LabelSelector to ```EqualsSelector { Label = app, Values = System.String[] }``` or to ```NotEqualsSelector { Label = srv, Values = System.String[] }``` instead of calling implicit to string convertor. The proposed pull request corrects this unpleasant behavior. Tests are attached. Co-authored-by: Christoph Bühler <[email protected]>
1 parent 8b3d822 commit d13cadf

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/KubeOps.KubernetesClient/LabelSelectors/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public static class Extensions
88
/// <param name="selectors">The list of selectors.</param>
99
/// <returns>A comma-joined string with all selectors converted to their expressions.</returns>
1010
public static string ToExpression(this IEnumerable<LabelSelector> selectors) =>
11-
string.Join(",", selectors);
11+
string.Join(",", selectors.Select(x => (string)x));
1212
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using KubeOps.KubernetesClient.LabelSelectors;
2+
3+
namespace KubeOps.KubernetesClient.Test;
4+
5+
public class LabelSelectorTest : IntegrationTestBase
6+
{
7+
[Fact]
8+
public void Sould_Return_Correct_Expression()
9+
{
10+
var labelSelectors = new LabelSelector[] {
11+
new EqualsSelector("app", Enumerable.Range(0,3).Select(x=>$"app-{x}").ToArray()),
12+
new NotEqualsSelector("srv", Enumerable.Range(0,2).Select(x=>$"service-{x}").ToArray())
13+
};
14+
15+
string expected = "app in (app-0,app-1,app-2),srv notin (service-0,service-1)";
16+
var actual = labelSelectors.ToExpression();
17+
Assert.Equal(expected, actual);
18+
}
19+
}

0 commit comments

Comments
 (0)