Style fix1 (#512)
* fix SA1505 and SA1508 * fix SA1116 * fix SA1009 * fix SA1019 * fix SA1127 * fix SA1128 * fix SA1134 * fix indent * allow CA2227 * fix CA1810 * using clean up * fix naming * fix CA1806 * fix await * Revert "fix CA1806" This reverts commit a3b465087fdaf26ec461272373ee9810a90de2cc. * fix dotnet format * allow SA1009
This commit is contained in:
@@ -18,7 +18,6 @@ using Microsoft.Rest;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Org.BouncyCastle.Pkcs;
|
||||
using Org.BouncyCastle.Security;
|
||||
using Remotion.Linq.Clauses;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -89,8 +88,9 @@ namespace k8s.Tests
|
||||
{
|
||||
var header = cxt.Request.Headers["Authorization"].FirstOrDefault();
|
||||
|
||||
var expect = new AuthenticationHeaderValue("Basic",
|
||||
Convert.ToBase64String(Encoding.UTF8.GetBytes($"{testName}:{testPassword}")))
|
||||
var expect = new AuthenticationHeaderValue(
|
||||
"Basic",
|
||||
Convert.ToBase64String(Encoding.UTF8.GetBytes($"{testName}:{testPassword}")))
|
||||
.ToString();
|
||||
|
||||
if (header != expect)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Nito.AsyncEx;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
@@ -262,7 +260,8 @@ namespace k8s.Tests
|
||||
// Write data to the buffer
|
||||
buffer.Write(this.writeData, 0, 0x03);
|
||||
|
||||
await TaskAssert.Completed(readTask,
|
||||
await TaskAssert.Completed(
|
||||
readTask,
|
||||
timeout: TimeSpan.FromMilliseconds(1000),
|
||||
message: "Timed out waiting for read task to complete.").ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using k8s;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Security;
|
||||
using System.Linq;
|
||||
|
||||
namespace k8s.Tests
|
||||
@@ -42,7 +39,8 @@ namespace k8s.Tests
|
||||
[Fact]
|
||||
public void LoadFromFilesRelativePath()
|
||||
{
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigWithRelativePathsFileName,
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(
|
||||
KubeConfigWithRelativePathsFileName,
|
||||
"federal-context");
|
||||
|
||||
// Just validate that this doesn't throw and private key is non-null
|
||||
@@ -70,7 +68,8 @@ namespace k8s.Tests
|
||||
[Fact]
|
||||
public void LoadFromInlineDataRelativePath()
|
||||
{
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigWithRelativePathsFileName,
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(
|
||||
KubeConfigWithRelativePathsFileName,
|
||||
"victorian-context");
|
||||
|
||||
// Just validate that this doesn't throw and private key is non-null
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Xunit;
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using k8s.Authentication;
|
||||
using Xunit;
|
||||
|
||||
namespace k8s.Tests
|
||||
{
|
||||
|
||||
@@ -161,7 +161,8 @@ namespace k8s.Tests
|
||||
public void CreatedFromPreLoadedConfig()
|
||||
{
|
||||
var k8sConfig =
|
||||
KubernetesClientConfiguration.LoadKubeConfig(new FileInfo("assets/kubeconfig.yml"),
|
||||
KubernetesClientConfiguration.LoadKubeConfig(
|
||||
new FileInfo("assets/kubeconfig.yml"),
|
||||
useRelativePaths: false);
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigObject(k8sConfig);
|
||||
Assert.NotNull(cfg.Host);
|
||||
@@ -173,7 +174,8 @@ namespace k8s.Tests
|
||||
[Fact]
|
||||
public void DefaultConfigurationLoaded()
|
||||
{
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(new FileInfo("assets/kubeconfig.yml"),
|
||||
var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(
|
||||
new FileInfo("assets/kubeconfig.yml"),
|
||||
useRelativePaths: false);
|
||||
Assert.NotNull(cfg.Host);
|
||||
}
|
||||
@@ -442,7 +444,8 @@ namespace k8s.Tests
|
||||
var filePath = Path.GetFullPath("assets/kubeconfig.relative.yml");
|
||||
var environmentVariable = "KUBECONFIG_LoadKubeConfigFromEnvironmentVariable_MultipleConfigs";
|
||||
|
||||
Environment.SetEnvironmentVariable(environmentVariable,
|
||||
Environment.SetEnvironmentVariable(
|
||||
environmentVariable,
|
||||
string.Concat(filePath, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ';' : ':', filePath));
|
||||
KubernetesClientConfiguration.KubeConfigEnvironmentVariable = environmentVariable;
|
||||
|
||||
@@ -576,7 +579,8 @@ namespace k8s.Tests
|
||||
{
|
||||
Assert.Equal(expected.Name, actual.Name);
|
||||
Assert.Equal(expected.ClusterEndpoint.CertificateAuthority, actual.ClusterEndpoint.CertificateAuthority);
|
||||
Assert.Equal(expected.ClusterEndpoint.CertificateAuthorityData,
|
||||
Assert.Equal(
|
||||
expected.ClusterEndpoint.CertificateAuthorityData,
|
||||
actual.ClusterEndpoint.CertificateAuthorityData);
|
||||
Assert.Equal(expected.ClusterEndpoint.Server, actual.ClusterEndpoint.Server);
|
||||
Assert.Equal(expected.ClusterEndpoint.SkipTlsVerify, actual.ClusterEndpoint.SkipTlsVerify);
|
||||
|
||||
@@ -83,7 +83,8 @@ namespace k8s.Tests.Logging
|
||||
throw new ArgumentNullException(nameof(formatter));
|
||||
}
|
||||
|
||||
TestOutput.WriteLine(string.Format("[{0}] {1}: {2}",
|
||||
TestOutput.WriteLine(string.Format(
|
||||
"[{0}] {1}: {2}",
|
||||
level,
|
||||
LoggerCategory,
|
||||
formatter(state, exception)));
|
||||
|
||||
@@ -75,7 +75,8 @@ namespace k8s.Tests.Mock
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override async Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buffer,
|
||||
public override async Task<WebSocketReceiveResult> ReceiveAsync(
|
||||
ArraySegment<byte> buffer,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (this.receiveBuffers.Count == 0)
|
||||
@@ -113,7 +114,8 @@ namespace k8s.Tests.Mock
|
||||
public override Task SendAsync(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
this.MessageSent?.Invoke(this,
|
||||
this.MessageSent?.Invoke(
|
||||
this,
|
||||
new MessageDataEventArgs()
|
||||
{
|
||||
Data = new MessageData()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace k8s.Tests.Mock.Server.Controllers
|
||||
|
||||
@@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace k8s.Tests.Mock.Server.Controllers
|
||||
|
||||
@@ -67,9 +67,9 @@ namespace k8s.Tests
|
||||
stdout: true,
|
||||
webSocketSubProtol: WebSocketProtocol.ChannelWebSocketProtocol,
|
||||
cancellationToken: TestCancellation).ConfigureAwait(false);
|
||||
Assert.Equal(WebSocketProtocol.ChannelWebSocketProtocol,
|
||||
clientSocket
|
||||
.SubProtocol); // For WebSockets, the Kubernetes API defaults to the binary channel (v1) protocol.
|
||||
Assert.Equal(
|
||||
WebSocketProtocol.ChannelWebSocketProtocol,
|
||||
clientSocket.SubProtocol); // For WebSockets, the Kubernetes API defaults to the binary channel (v1) protocol.
|
||||
|
||||
testOutput.WriteLine(
|
||||
$"Client socket connected (socket state is {clientSocket.State}). Waiting for server-side socket to become available...");
|
||||
@@ -200,8 +200,9 @@ namespace k8s.Tests
|
||||
|
||||
using (Kubernetes client = kubernetesMock.Object)
|
||||
{
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.NamespacedPodExecAsync("pod-name",
|
||||
"pod-namespace", "my-container", command, false, null, CancellationToken.None))
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.NamespacedPodExecAsync(
|
||||
"pod-name",
|
||||
"pod-namespace", "my-container", command, false, null, CancellationToken.None))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -223,8 +224,9 @@ namespace k8s.Tests
|
||||
|
||||
using (Kubernetes client = kubernetesMock.Object)
|
||||
{
|
||||
var ex = await Assert.ThrowsAsync<KubernetesException>(() => client.NamespacedPodExecAsync("pod-name",
|
||||
"pod-namespace", "my-container", command, false, handler, CancellationToken.None))
|
||||
var ex = await Assert.ThrowsAsync<KubernetesException>(() => client.NamespacedPodExecAsync(
|
||||
"pod-name",
|
||||
"pod-namespace", "my-container", command, false, handler, CancellationToken.None))
|
||||
.ConfigureAwait(false);
|
||||
Assert.Same(status, ex.Status);
|
||||
}
|
||||
@@ -269,8 +271,9 @@ namespace k8s.Tests
|
||||
|
||||
using (Kubernetes client = kubernetesMock.Object)
|
||||
{
|
||||
var ex = await Assert.ThrowsAsync<Exception>(() => client.NamespacedPodExecAsync("pod-name",
|
||||
"pod-namespace", "my-container", command, false, handler, CancellationToken.None))
|
||||
var ex = await Assert.ThrowsAsync<Exception>(() => client.NamespacedPodExecAsync(
|
||||
"pod-name",
|
||||
"pod-namespace", "my-container", command, false, handler, CancellationToken.None))
|
||||
.ConfigureAwait(false);
|
||||
Assert.Same(exception, ex);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.Tests.Mock;
|
||||
@@ -37,7 +36,8 @@ namespace k8s.Tests
|
||||
stream.Write(b, 0, b.Length);
|
||||
|
||||
// Send 100 bytes, expect 1 (channel index) + 100 (payload) = 101 bytes
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 101).ConfigureAwait(false),
|
||||
Assert.True(
|
||||
await WaitForAsync(() => sentBuffer.Count == 101).ConfigureAwait(false),
|
||||
$"Demuxer error: expect to send 101 bytes, but actually send {sentBuffer.Count} bytes.");
|
||||
Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!");
|
||||
Assert.True(sentBuffer[1] == 0xEF, "Incorrect payload!");
|
||||
@@ -63,7 +63,8 @@ namespace k8s.Tests
|
||||
stream.Write(b, 0, b.Length);
|
||||
|
||||
// Send 300 bytes in 2 messages, expect 1 (channel index) * 2 + 300 (payload) = 302 bytes
|
||||
Assert.True(await WaitForAsync(() => sentBuffer.Count == 302).ConfigureAwait(false),
|
||||
Assert.True(
|
||||
await WaitForAsync(() => sentBuffer.Count == 302).ConfigureAwait(false),
|
||||
$"Demuxer error: expect to send 302 bytes, but actually send {sentBuffer.Count} bytes.");
|
||||
Assert.True(sentBuffer[0] == channelIndex, "The first sent byte is not channel index!");
|
||||
Assert.True(sentBuffer[1] == 0xEF, "The first part of payload incorrect!");
|
||||
@@ -119,7 +120,8 @@ namespace k8s.Tests
|
||||
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
Assert.True(
|
||||
receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
Assert.True(receivedBuffer[0] == 0xAA, "The first payload incorrect!");
|
||||
Assert.True(receivedBuffer[98] == 0xAA, "The first payload incorrect!");
|
||||
@@ -178,7 +180,8 @@ namespace k8s.Tests
|
||||
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
Assert.True(
|
||||
receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
Assert.True(receivedBuffer[0] == 0xB1, "The first payload incorrect!");
|
||||
Assert.True(receivedBuffer[96] == 0xB1, "The first payload incorrect!");
|
||||
@@ -237,7 +240,8 @@ namespace k8s.Tests
|
||||
|
||||
await t.ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer.Count == expectedCount,
|
||||
Assert.True(
|
||||
receivedBuffer.Count == expectedCount,
|
||||
$"Demuxer error: expect to receive {expectedCount} bytes, but actually got {receivedBuffer.Count} bytes.");
|
||||
Assert.True(receivedBuffer[0] == 0xC2, "The first payload incorrect!");
|
||||
Assert.True(receivedBuffer[98] == 0xC2, "The first payload incorrect!");
|
||||
@@ -320,9 +324,11 @@ namespace k8s.Tests
|
||||
});
|
||||
await Task.WhenAll(t1, t2, t3).ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer1.Count == expectedCount1,
|
||||
Assert.True(
|
||||
receivedBuffer1.Count == expectedCount1,
|
||||
$"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes.");
|
||||
Assert.True(receivedBuffer2.Count == expectedCount2,
|
||||
Assert.True(
|
||||
receivedBuffer2.Count == expectedCount2,
|
||||
$"Demuxer error: expect to receive {expectedCount2} bytes, but actually got {receivedBuffer2.Count} bytes.");
|
||||
Assert.True(receivedBuffer1[0] == 0xD1, "The first payload incorrect!");
|
||||
Assert.True(receivedBuffer1[98] == 0xD1, "The first payload incorrect!");
|
||||
@@ -409,9 +415,11 @@ namespace k8s.Tests
|
||||
});
|
||||
await Task.WhenAll(t1, t2, t3).ConfigureAwait(false);
|
||||
|
||||
Assert.True(receivedBuffer1.Count == expectedCount1,
|
||||
Assert.True(
|
||||
receivedBuffer1.Count == expectedCount1,
|
||||
$"Demuxer error: expect to receive {expectedCount1} bytes, but actually got {receivedBuffer1.Count} bytes.");
|
||||
Assert.True(receivedBuffer2.Count == expectedCount2,
|
||||
Assert.True(
|
||||
receivedBuffer2.Count == expectedCount2,
|
||||
$"Demuxer error: expect to receive {expectedCount2} bytes, but actually got {receivedBuffer2.Count} bytes.");
|
||||
Assert.True(receivedBuffer1[0] == 0xE1, "The first payload incorrect!");
|
||||
Assert.True(receivedBuffer1[96] == 0xE1, "The first payload incorrect!");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using k8s.Authentication;
|
||||
using Xunit;
|
||||
|
||||
namespace k8s.Tests
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using k8s.Models;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
@@ -8,11 +8,9 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.Exceptions;
|
||||
using k8s.Models;
|
||||
using k8s.Tests.Mock;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Nito.AsyncEx;
|
||||
@@ -430,7 +428,8 @@ namespace k8s.Tests
|
||||
{
|
||||
internal bool Called { get; private set; }
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Called = true;
|
||||
|
||||
@@ -179,7 +179,8 @@ namespace k8s.Tests
|
||||
{
|
||||
if (received.IsFaulted)
|
||||
{
|
||||
testOutput.WriteLine("Server socket operation to receive Close message failed: {0}",
|
||||
testOutput.WriteLine(
|
||||
"Server socket operation to receive Close message failed: {0}",
|
||||
received.Exception.Flatten().InnerExceptions[0]);
|
||||
}
|
||||
else if (received.IsCanceled)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using k8s.Models;
|
||||
using Xunit;
|
||||
@@ -114,7 +113,8 @@ metadata:
|
||||
var pod = new V1Pod() { ApiVersion = "v1", Kind = "Pod", Metadata = new V1ObjectMeta() { Name = "foo" } };
|
||||
|
||||
var yaml = Yaml.SaveToString(pod);
|
||||
Assert.Equal(ToLines(@"apiVersion: v1
|
||||
Assert.Equal(
|
||||
ToLines(@"apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: foo"), ToLines(yaml));
|
||||
@@ -131,7 +131,8 @@ metadata:
|
||||
};
|
||||
|
||||
var yaml = Yaml.SaveToString(pod);
|
||||
Assert.Equal(ToLines(@"apiVersion: v1
|
||||
Assert.Equal(
|
||||
ToLines(@"apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: foo
|
||||
@@ -170,7 +171,8 @@ metadata:
|
||||
};
|
||||
|
||||
var yaml = Yaml.SaveToString(pod);
|
||||
Assert.Equal(ToLines(@"apiVersion: v1
|
||||
Assert.Equal(
|
||||
ToLines(@"apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: foo
|
||||
|
||||
Reference in New Issue
Block a user