Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 87488b4

Browse files
tg123JonJam
authored andcommitted
fix test case fail on windows (kubernetes-client#177)
* fix test case fail on windows * fix cert not working on windows * changed to RuntimeInformation to see if osx * change to a more common way to deal with line ending (due to git autocrlf)
1 parent 94cf799 commit 87488b4

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

tests/KubernetesClient.Tests/AuthTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Http.Headers;
6+
using System.Runtime.InteropServices;
67
using System.Security.Cryptography;
78
using System.Security.Cryptography.X509Certificates;
89
using System.Text;
@@ -177,10 +178,18 @@ public void Cert()
177178
var clientCertificateData = File.ReadAllText("assets/client-certificate-data.txt");
178179

179180
X509Certificate2 serverCertificate = null;
180-
using (MemoryStream serverCertificateStream = new MemoryStream(Convert.FromBase64String(serverCertificateData)))
181+
182+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
181183
{
182-
serverCertificate = OpenCertificateStore(serverCertificateStream);
184+
using (MemoryStream serverCertificateStream = new MemoryStream(Convert.FromBase64String(serverCertificateData)))
185+
{
186+
serverCertificate = OpenCertificateStore(serverCertificateStream);
187+
}
183188
}
189+
else
190+
{
191+
serverCertificate = new X509Certificate2(Convert.FromBase64String(serverCertificateData), "");
192+
}
184193

185194
var clientCertificate = new X509Certificate2(Convert.FromBase64String(clientCertificateData), "");
186195

tests/KubernetesClient.Tests/YamlTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.IO;
4+
using System.Linq;
25
using k8s.Models;
36
using Xunit;
47

@@ -50,10 +53,26 @@ public void WriteToString()
5053
};
5154

5255
var yaml = Yaml.SaveToString(pod);
53-
Assert.Equal(@"apiVersion: v1
56+
Assert.True(ToLines(@"apiVersion: v1
5457
kind: Pod
5558
metadata:
56-
name: foo", yaml);
59+
name: foo").SequenceEqual(ToLines(yaml)));
60+
}
61+
62+
private static IEnumerable<string> ToLines(string s)
63+
{
64+
using (var reader = new StringReader(s))
65+
{
66+
for (;;)
67+
{
68+
var line = reader.ReadLine();
69+
if (line == null)
70+
{
71+
yield break;
72+
}
73+
yield return line;
74+
}
75+
}
5776
}
5877

5978
[Fact]

0 commit comments

Comments
 (0)