From f615b5b4595a35aa6ddc5fed3c396cabdc3f3efa Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com> Date: Fri, 16 Sep 2022 01:21:21 +0200 Subject: [PATCH] Fix some compilation warnings (#1010) * Fixe some summary warning * Fixed more warning * Uniformed example projects code * Uniformed test projects code * Fix OperatingSystems enum and GenericType summaries --- examples/attach/Attach.cs | 6 +-- examples/cp/Cp.cs | 12 +++--- examples/csrApproval/Program.cs | 16 ++++---- examples/exec/Exec.cs | 6 +-- examples/generic/Generic.cs | 4 +- examples/labels/PodList.cs | 2 +- examples/logs/Logs.cs | 2 +- examples/namespace/NamespaceExample.cs | 4 +- examples/patch/Program.cs | 4 +- examples/portforward/PortForward.cs | 38 +++++++++++-------- examples/prometheus/Prometheus.cs | 6 +-- examples/restart/Program.cs | 4 +- examples/simple/PodList.cs | 2 +- examples/watch/Program.cs | 6 +-- examples/yaml/Program.cs | 9 +++-- .../KubernetesMetricsExtensions.cs | 15 ++++++++ .../ResourceLock/ConfigMapLock.cs | 20 ++++++++-- .../ResourceLock/EndpointsLock.cs | 17 ++++++++- .../LeaderElection/ResourceLock/LeaseLock.cs | 17 ++++++++- tests/E2E.Tests/MinikubeTests.cs | 18 ++++----- .../SimpleTests.cs | 4 +- tests/KubernetesClient.Tests/AuthTests.cs | 22 +++++------ .../KubernetesClient.Tests/ByteBufferTests.cs | 3 +- .../KubernetesClient.Tests/CertUtilsTests.cs | 4 +- .../ExternalExecutionTests.cs | 2 +- .../GcpTokenProviderTests.cs | 4 +- .../KubernetesClientConfigurationTests.cs | 21 +++++----- .../KubernetesYamlTests.cs | 2 +- .../LeaderElection/LeaderElectionTests.cs | 4 +- .../Logging/TestOutputLogger.cs | 9 ++--- .../Mock/MockKubeApiServer.cs | 8 ++-- .../Mock/MockWebSocket.cs | 6 +-- .../Server/Controllers/PodExecController.cs | 10 +---- .../Controllers/PodPortForwardController.cs | 10 +---- .../ModelExtensionTests.cs | 2 +- tests/KubernetesClient.Tests/OidcAuthTests.cs | 4 +- .../OperatingSystems.cs | 5 +++ tests/KubernetesClient.Tests/PodExecTests.cs | 5 +-- .../QuantityValueTests.cs | 2 +- .../StreamDemuxerTests.cs | 2 +- .../TokenFileAuthTests.cs | 4 +- .../VersionConverterTests.cs | 4 +- tests/KubernetesClient.Tests/WatchTests.cs | 8 ++-- .../WebSocketTestBase.cs | 7 +--- tests/SkipTestLogger/SkipTestLogger.cs | 4 +- 45 files changed, 210 insertions(+), 154 deletions(-) diff --git a/examples/attach/Attach.cs b/examples/attach/Attach.cs index fb24866..a53b5da 100755 --- a/examples/attach/Attach.cs +++ b/examples/attach/Attach.cs @@ -1,7 +1,7 @@ -using System; -using System.Threading.Tasks; using k8s; using k8s.Models; +using System; +using System.Threading.Tasks; namespace attach { @@ -18,7 +18,7 @@ namespace attach await AttachToPod(client, pod).ConfigureAwait(false); } - private async static Task AttachToPod(IKubernetes client, V1Pod pod) + private static async Task AttachToPod(IKubernetes client, V1Pod pod) { var webSocket = await client.WebSocketNamespacedPodAttachAsync(pod.Metadata.Name, "default", diff --git a/examples/cp/Cp.cs b/examples/cp/Cp.cs index c6b44b9..b7dd5b2 100644 --- a/examples/cp/Cp.cs +++ b/examples/cp/Cp.cs @@ -1,11 +1,11 @@ -using System; -using System.IO; -using System.Threading.Tasks; +using ICSharpCode.SharpZipLib.Tar; using k8s; -using ICSharpCode.SharpZipLib.Tar; -using System.Threading; +using System; +using System.IO; using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace cp { @@ -57,7 +57,7 @@ namespace cp using (var memoryStream = new MemoryStream()) { using (var inputFileStream = File.OpenRead(sourceFilePath)) - using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default)) + using (var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default)) { tarOutputStream.IsStreamOwner = false; diff --git a/examples/csrApproval/Program.cs b/examples/csrApproval/Program.cs index 461bb31..b4f1548 100644 --- a/examples/csrApproval/Program.cs +++ b/examples/csrApproval/Program.cs @@ -1,11 +1,11 @@ -using System.Net; +using Json.Patch; +using k8s; +using k8s.Models; +using System.Net; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Text.Json; -using Json.Patch; -using k8s; -using k8s.Models; string GenerateCertificate(string name) { @@ -18,10 +18,10 @@ string GenerateCertificate(string name) var distinguishedName = new X500DistinguishedName(name); using var rsa = RSA.Create(4096); - var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256,RSASignaturePadding.Pkcs1); + var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); - request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature , false)); - request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new ("1.3.6.1.5.5.7.3.1") }, false)); + request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature, false)); + request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new("1.3.6.1.5.5.7.3.1") }, false)); request.CertificateExtensions.Add(sanBuilder.Build()); var csr = request.CreateSigningRequest(); var pemKey = "-----BEGIN CERTIFICATE REQUEST-----\r\n" + @@ -36,7 +36,7 @@ IKubernetes client = new Kubernetes(config); Console.WriteLine("Starting Request!"); var name = "demo"; var x509 = GenerateCertificate(name); -var encodedCsr= Encoding.UTF8.GetBytes(x509); +var encodedCsr = Encoding.UTF8.GetBytes(x509); var request = new V1CertificateSigningRequest { diff --git a/examples/exec/Exec.cs b/examples/exec/Exec.cs index 2d4ad66..9fdfc73 100755 --- a/examples/exec/Exec.cs +++ b/examples/exec/Exec.cs @@ -1,7 +1,7 @@ -using System; -using System.Threading.Tasks; using k8s; using k8s.Models; +using System; +using System.Threading.Tasks; namespace exec { @@ -18,7 +18,7 @@ namespace exec await ExecInPod(client, pod).ConfigureAwait(false); } - private async static Task ExecInPod(IKubernetes client, V1Pod pod) + private static async Task ExecInPod(IKubernetes client, V1Pod pod) { var webSocket = await client.WebSocketNamespacedPodExecAsync(pod.Metadata.Name, "default", "ls", diff --git a/examples/generic/Generic.cs b/examples/generic/Generic.cs index de4525c..41f91b3 100644 --- a/examples/generic/Generic.cs +++ b/examples/generic/Generic.cs @@ -1,7 +1,7 @@ -using System; -using System.Threading.Tasks; using k8s; using k8s.Models; +using System; +using System.Threading.Tasks; namespace exec { diff --git a/examples/labels/PodList.cs b/examples/labels/PodList.cs index 341b520..2d59e90 100755 --- a/examples/labels/PodList.cs +++ b/examples/labels/PodList.cs @@ -1,6 +1,6 @@ +using k8s; using System; using System.Collections.Generic; -using k8s; namespace simple { diff --git a/examples/logs/Logs.cs b/examples/logs/Logs.cs index 8244f53..ea23fa0 100755 --- a/examples/logs/Logs.cs +++ b/examples/logs/Logs.cs @@ -1,6 +1,6 @@ +using k8s; using System; using System.Threading.Tasks; -using k8s; namespace logs { diff --git a/examples/namespace/NamespaceExample.cs b/examples/namespace/NamespaceExample.cs index fc3d3e3..351453a 100644 --- a/examples/namespace/NamespaceExample.cs +++ b/examples/namespace/NamespaceExample.cs @@ -1,8 +1,8 @@ +using k8s; +using k8s.Models; using System; using System.Net; using System.Threading.Tasks; -using k8s; -using k8s.Models; namespace @namespace { diff --git a/examples/patch/Program.cs b/examples/patch/Program.cs index fa5ff1d..7958fcc 100644 --- a/examples/patch/Program.cs +++ b/examples/patch/Program.cs @@ -1,7 +1,7 @@ -using System; -using System.Linq; using k8s; using k8s.Models; +using System; +using System.Linq; namespace patch { diff --git a/examples/portforward/PortForward.cs b/examples/portforward/PortForward.cs index ecbf6fd..fe9485d 100644 --- a/examples/portforward/PortForward.cs +++ b/examples/portforward/PortForward.cs @@ -1,10 +1,10 @@ +using k8s; +using k8s.Models; using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; -using k8s; -using k8s.Models; namespace portforward { @@ -21,40 +21,47 @@ namespace portforward await Forward(client, pod); } - private async static Task Forward(IKubernetes client, V1Pod pod) { + private static async Task Forward(IKubernetes client, V1Pod pod) + { // Note this is single-threaded, it won't handle concurrent requests well... - var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] {80}, "v4.channel.k8s.io"); + var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] { 80 }, "v4.channel.k8s.io"); var demux = new StreamDemuxer(webSocket, StreamType.PortForward); demux.Start(); var stream = demux.GetStream((byte?)0, (byte?)0); IPAddress ipAddress = IPAddress.Loopback; - IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8080); - Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - listener.Bind(localEndPoint); + IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8080); + Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + listener.Bind(localEndPoint); listener.Listen(100); Socket handler = null; // Note this will only accept a single connection - var accept = Task.Run(() => { - while (true) { + var accept = Task.Run(() => + { + while (true) + { handler = listener.Accept(); var bytes = new byte[4096]; - while (true) { + while (true) + { int bytesRec = handler.Receive(bytes); stream.Write(bytes, 0, bytesRec); - if (bytesRec == 0 || Encoding.ASCII.GetString(bytes,0,bytesRec).IndexOf("") > -1) { - break; + if (bytesRec == 0 || Encoding.ASCII.GetString(bytes, 0, bytesRec).IndexOf("") > -1) + { + break; } } } }); - var copy = Task.Run(() => { + var copy = Task.Run(() => + { var buff = new byte[4096]; - while (true) { + while (true) + { var read = stream.Read(buff, 0, 4096); handler.Send(buff, read, 0); } @@ -62,7 +69,8 @@ namespace portforward await accept; await copy; - if (handler != null) { + if (handler != null) + { handler.Close(); } listener.Close(); diff --git a/examples/prometheus/Prometheus.cs b/examples/prometheus/Prometheus.cs index 95993b0..0a3111e 100755 --- a/examples/prometheus/Prometheus.cs +++ b/examples/prometheus/Prometheus.cs @@ -1,9 +1,9 @@ -using System; -using System.Net.Http; -using System.Threading; using k8s; using k8s.Monitoring; using Prometheus; +using System; +using System.Net.Http; +using System.Threading; namespace prom { diff --git a/examples/restart/Program.cs b/examples/restart/Program.cs index 74f2aeb..b6e7a6f 100644 --- a/examples/restart/Program.cs +++ b/examples/restart/Program.cs @@ -1,7 +1,7 @@ -using System.Text.Json; -using Json.Patch; +using Json.Patch; using k8s; using k8s.Models; +using System.Text.Json; async Task RestartDaemonSetAsync(string name, string @namespace, IKubernetes client) { diff --git a/examples/simple/PodList.cs b/examples/simple/PodList.cs index 021f368..b9eb3cd 100755 --- a/examples/simple/PodList.cs +++ b/examples/simple/PodList.cs @@ -1,5 +1,5 @@ -using System; using k8s; +using System; namespace simple { diff --git a/examples/watch/Program.cs b/examples/watch/Program.cs index 2ef5e58..525cbec 100644 --- a/examples/watch/Program.cs +++ b/examples/watch/Program.cs @@ -1,14 +1,14 @@ +using k8s; +using k8s.Models; using System; using System.Threading; using System.Threading.Tasks; -using k8s; -using k8s.Models; namespace watch { internal class Program { - private async static Task Main(string[] args) + private static async Task Main(string[] args) { var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); diff --git a/examples/yaml/Program.cs b/examples/yaml/Program.cs index af27ec9..a724f30 100644 --- a/examples/yaml/Program.cs +++ b/examples/yaml/Program.cs @@ -1,14 +1,14 @@ +using k8s; +using k8s.Models; using System; using System.Collections.Generic; using System.Threading.Tasks; -using k8s; -using k8s.Models; namespace yaml { internal class Program { - private async static Task Main(string[] args) + private static async Task Main(string[] args) { var typeMap = new Dictionary(); typeMap.Add("v1/Pod", typeof(V1Pod)); @@ -17,7 +17,8 @@ namespace yaml var objects = await KubernetesYaml.LoadAllFromFileAsync(args[0], typeMap); - foreach (var obj in objects) { + foreach (var obj in objects) + { Console.WriteLine(obj); } } diff --git a/src/KubernetesClient/KubernetesMetricsExtensions.cs b/src/KubernetesClient/KubernetesMetricsExtensions.cs index 495f0bd..a5dec88 100644 --- a/src/KubernetesClient/KubernetesMetricsExtensions.cs +++ b/src/KubernetesClient/KubernetesMetricsExtensions.cs @@ -15,6 +15,11 @@ namespace k8s /// the metrics public static async Task GetKubernetesNodesMetricsAsync(this IKubernetes kubernetes) { + if (kubernetes is null) + { + throw new ArgumentNullException(nameof(kubernetes)); + } + var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "nodes", string.Empty).ConfigureAwait(false); return customObject.Deserialize(); } @@ -26,6 +31,11 @@ namespace k8s /// the metrics public static async Task GetKubernetesPodsMetricsAsync(this IKubernetes kubernetes) { + if (kubernetes is null) + { + throw new ArgumentNullException(nameof(kubernetes)); + } + var customObject = (JsonElement)await kubernetes.CustomObjects.GetClusterCustomObjectAsync("metrics.k8s.io", "v1beta1", "pods", string.Empty).ConfigureAwait(false); return customObject.Deserialize(); } @@ -38,6 +48,11 @@ namespace k8s /// the metrics public static async Task GetKubernetesPodsMetricsByNamespaceAsync(this IKubernetes kubernetes, string namespaceParameter) { + if (kubernetes is null) + { + throw new ArgumentNullException(nameof(kubernetes)); + } + var customObject = (JsonElement)await kubernetes.CustomObjects.GetNamespacedCustomObjectAsync("metrics.k8s.io", "v1beta1", namespaceParameter, "pods", string.Empty).ConfigureAwait(false); return customObject.Deserialize(); } diff --git a/src/KubernetesClient/LeaderElection/ResourceLock/ConfigMapLock.cs b/src/KubernetesClient/LeaderElection/ResourceLock/ConfigMapLock.cs index e823d76..b5e7a26 100644 --- a/src/KubernetesClient/LeaderElection/ResourceLock/ConfigMapLock.cs +++ b/src/KubernetesClient/LeaderElection/ResourceLock/ConfigMapLock.cs @@ -1,6 +1,6 @@ +using k8s.Models; using System.Threading; using System.Threading.Tasks; -using k8s.Models; namespace k8s.LeaderElection.ResourceLock { @@ -15,6 +15,11 @@ namespace k8s.LeaderElection.ResourceLock string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoreV1.ReadNamespacedConfigMapAsync(name, namespaceParameter, cancellationToken: cancellationToken); } @@ -22,6 +27,11 @@ namespace k8s.LeaderElection.ResourceLock string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoreV1.CreateNamespacedConfigMapAsync(obj, namespaceParameter, cancellationToken: cancellationToken); } @@ -29,8 +39,12 @@ namespace k8s.LeaderElection.ResourceLock string namespaceParameter, CancellationToken cancellationToken) { - return client.CoreV1.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter, - cancellationToken: cancellationToken); + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + + return client.CoreV1.ReplaceNamespacedConfigMapAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken); } } } diff --git a/src/KubernetesClient/LeaderElection/ResourceLock/EndpointsLock.cs b/src/KubernetesClient/LeaderElection/ResourceLock/EndpointsLock.cs index c5eaa87..1ebf64f 100644 --- a/src/KubernetesClient/LeaderElection/ResourceLock/EndpointsLock.cs +++ b/src/KubernetesClient/LeaderElection/ResourceLock/EndpointsLock.cs @@ -1,6 +1,6 @@ +using k8s.Models; using System.Threading; using System.Threading.Tasks; -using k8s.Models; namespace k8s.LeaderElection.ResourceLock { @@ -13,18 +13,33 @@ namespace k8s.LeaderElection.ResourceLock protected override Task ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoreV1.ReadNamespacedEndpointsAsync(name, namespaceParameter, cancellationToken: cancellationToken); } protected override Task CreateMetaObjectAsync(IKubernetes client, V1Endpoints obj, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoreV1.CreateNamespacedEndpointsAsync(obj, namespaceParameter, cancellationToken: cancellationToken); } protected override Task ReplaceMetaObjectAsync(IKubernetes client, V1Endpoints obj, string name, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoreV1.ReplaceNamespacedEndpointsAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken); } } diff --git a/src/KubernetesClient/LeaderElection/ResourceLock/LeaseLock.cs b/src/KubernetesClient/LeaderElection/ResourceLock/LeaseLock.cs index 4365868..35befc0 100644 --- a/src/KubernetesClient/LeaderElection/ResourceLock/LeaseLock.cs +++ b/src/KubernetesClient/LeaderElection/ResourceLock/LeaseLock.cs @@ -1,6 +1,6 @@ +using k8s.Models; using System.Threading; using System.Threading.Tasks; -using k8s.Models; namespace k8s.LeaderElection.ResourceLock { @@ -14,6 +14,11 @@ namespace k8s.LeaderElection.ResourceLock protected override Task ReadMetaObjectAsync(IKubernetes client, string name, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoordinationV1.ReadNamespacedLeaseAsync(name, namespaceParameter, cancellationToken: cancellationToken); } @@ -61,12 +66,22 @@ namespace k8s.LeaderElection.ResourceLock protected override Task CreateMetaObjectAsync(IKubernetes client, V1Lease obj, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoordinationV1.CreateNamespacedLeaseAsync(obj, namespaceParameter, cancellationToken: cancellationToken); } protected override Task ReplaceMetaObjectAsync(IKubernetes client, V1Lease obj, string name, string namespaceParameter, CancellationToken cancellationToken) { + if (client is null) + { + throw new ArgumentNullException(nameof(client)); + } + return client.CoordinationV1.ReplaceNamespacedLeaseAsync(obj, name, namespaceParameter, cancellationToken: cancellationToken); } } diff --git a/tests/E2E.Tests/MinikubeTests.cs b/tests/E2E.Tests/MinikubeTests.cs index bee75e8..1ee33a4 100644 --- a/tests/E2E.Tests/MinikubeTests.cs +++ b/tests/E2E.Tests/MinikubeTests.cs @@ -1,22 +1,22 @@ +using ICSharpCode.SharpZipLib.Tar; +using Json.Patch; +using k8s.Autorest; +using k8s.LeaderElection; +using k8s.LeaderElection.ResourceLock; +using k8s.Models; +using Nito.AsyncEx; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Security.Cryptography; +using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Json.Patch; -using k8s.LeaderElection; -using k8s.LeaderElection.ResourceLock; -using k8s.Models; -using k8s.Autorest; -using Nito.AsyncEx; using Xunit; -using ICSharpCode.SharpZipLib.Tar; -using System.Text; -using System.Security.Cryptography; namespace k8s.E2E { diff --git a/tests/KubernetesClient.Classic.Tests/SimpleTests.cs b/tests/KubernetesClient.Classic.Tests/SimpleTests.cs index aadfc89..b03c936 100644 --- a/tests/KubernetesClient.Classic.Tests/SimpleTests.cs +++ b/tests/KubernetesClient.Classic.Tests/SimpleTests.cs @@ -1,9 +1,9 @@ +using k8s.Models; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Xunit; -using k8s.Models; namespace k8s.tests; @@ -12,7 +12,7 @@ public class BasicTests // TODO: fail to setup asp.net core 6 on net48 private class DummyHttpServer : System.IDisposable { - private TcpListener server; + private readonly TcpListener server; private readonly Task loop; private volatile bool running = false; diff --git a/tests/KubernetesClient.Tests/AuthTests.cs b/tests/KubernetesClient.Tests/AuthTests.cs index 034b891..6a79aa1 100644 --- a/tests/KubernetesClient.Tests/AuthTests.cs +++ b/tests/KubernetesClient.Tests/AuthTests.cs @@ -1,3 +1,14 @@ +using k8s.Authentication; +using k8s.Autorest; +using k8s.Exceptions; +using k8s.KubeConfigModels; +using k8s.Models; +using k8s.Tests.Mock; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Org.BouncyCastle.Crypto.Parameters; +using Org.BouncyCastle.Pkcs; +using Org.BouncyCastle.Security; using System; using System.Collections.Generic; using System.IO; @@ -9,17 +20,6 @@ using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; -using k8s.Authentication; -using k8s.Exceptions; -using k8s.KubeConfigModels; -using k8s.Models; -using k8s.Tests.Mock; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Server.Kestrel.Https; -using k8s.Autorest; -using Org.BouncyCastle.Crypto.Parameters; -using Org.BouncyCastle.Pkcs; -using Org.BouncyCastle.Security; using Xunit; using Xunit.Abstractions; diff --git a/tests/KubernetesClient.Tests/ByteBufferTests.cs b/tests/KubernetesClient.Tests/ByteBufferTests.cs index 0898d76..223382b 100644 --- a/tests/KubernetesClient.Tests/ByteBufferTests.cs +++ b/tests/KubernetesClient.Tests/ByteBufferTests.cs @@ -244,8 +244,7 @@ namespace k8s.Tests /// Tests a call to when no data is available; and makes /// sure the call blocks until data is available. /// - /// A representing the asynchronous unit test. - /// A representing the asynchronous unit test. + /// A representing the asynchronous unit test. [Fact] public async Task ReadBlocksUntilDataAvailableTest() { diff --git a/tests/KubernetesClient.Tests/CertUtilsTests.cs b/tests/KubernetesClient.Tests/CertUtilsTests.cs index 0a20e92..ca09ff7 100644 --- a/tests/KubernetesClient.Tests/CertUtilsTests.cs +++ b/tests/KubernetesClient.Tests/CertUtilsTests.cs @@ -1,7 +1,7 @@ using System; -using Xunit; -using System.Security.Cryptography.X509Certificates; using System.Linq; +using System.Security.Cryptography.X509Certificates; +using Xunit; namespace k8s.Tests { diff --git a/tests/KubernetesClient.Tests/ExternalExecutionTests.cs b/tests/KubernetesClient.Tests/ExternalExecutionTests.cs index dadc000..f4b101f 100644 --- a/tests/KubernetesClient.Tests/ExternalExecutionTests.cs +++ b/tests/KubernetesClient.Tests/ExternalExecutionTests.cs @@ -1,6 +1,6 @@ +using k8s.KubeConfigModels; using System.Collections.Generic; using System.Text.Json; -using k8s.KubeConfigModels; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs b/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs index 8d6efc7..5424225 100644 --- a/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs +++ b/tests/KubernetesClient.Tests/GcpTokenProviderTests.cs @@ -1,9 +1,9 @@ +using FluentAssertions; +using k8s.Authentication; using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using FluentAssertions; -using k8s.Authentication; namespace k8s.Tests { diff --git a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs index aea79cd..3205c07 100644 --- a/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs +++ b/tests/KubernetesClient.Tests/KubernetesClientConfigurationTests.cs @@ -33,6 +33,8 @@ namespace k8s.Tests /// /// Check if host is properly loaded, per context /// + /// Context to retreive the configuration + /// Host to check [Theory] [InlineData("federal-context", "https://horse.org:4443")] [InlineData("queen-anne-context", "https://pig.org:443")] @@ -46,6 +48,8 @@ namespace k8s.Tests /// /// Check if namespace is properly loaded, per context /// + /// Context to retreive the configuration + /// Namespace to check [Theory] [InlineData("federal-context", "chisel-ns")] [InlineData("queen-anne-context", "saw-ns")] @@ -59,8 +63,8 @@ namespace k8s.Tests /// /// Checks if user-based token is loaded properly from the config file, per context /// - /// - /// + /// Context to retreive the configuration + /// User authentication token [Theory] [InlineData("queen-anne-context", "black-token")] public void ContextUserToken(string context, string token) @@ -92,7 +96,7 @@ namespace k8s.Tests /// /// Checks for loading of elliptical curve keys /// - /// + /// Context to retreive the configuration [Theory] [InlineData("elliptic-context")] public void ContextEllipticKey(string context) @@ -383,11 +387,10 @@ namespace k8s.Tests [Fact] public void DefaultConfigurationAsStreamLoaded() { - using (var stream = File.OpenRead("assets/kubeconfig.yml")) - { - var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(stream); - Assert.NotNull(cfg.Host); - } + using var stream = File.OpenRead("assets/kubeconfig.yml"); + + var cfg = KubernetesClientConfiguration.BuildConfigFromConfigFile(stream); + Assert.NotNull(cfg.Host); } /// @@ -408,7 +411,7 @@ namespace k8s.Tests { var path = Path.GetFullPath("assets/kubeconfig.cluster-extensions.yml"); - var cfg = await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(path)).ConfigureAwait(false); + _ = await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(path)).ConfigureAwait(false); } [Fact] diff --git a/tests/KubernetesClient.Tests/KubernetesYamlTests.cs b/tests/KubernetesClient.Tests/KubernetesYamlTests.cs index a9563a9..9c07e73 100644 --- a/tests/KubernetesClient.Tests/KubernetesYamlTests.cs +++ b/tests/KubernetesClient.Tests/KubernetesYamlTests.cs @@ -1,9 +1,9 @@ +using k8s.Models; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; -using k8s.Models; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/LeaderElection/LeaderElectionTests.cs b/tests/KubernetesClient.Tests/LeaderElection/LeaderElectionTests.cs index 5da816a..3bac7e6 100644 --- a/tests/KubernetesClient.Tests/LeaderElection/LeaderElectionTests.cs +++ b/tests/KubernetesClient.Tests/LeaderElection/LeaderElectionTests.cs @@ -1,10 +1,10 @@ +using k8s.LeaderElection; +using Moq; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using k8s.LeaderElection; -using Moq; using Xunit; using Xunit.Abstractions; diff --git a/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs b/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs index f4f384a..39e0bb9 100644 --- a/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs +++ b/tests/KubernetesClient.Tests/Logging/TestOutputLogger.cs @@ -26,11 +26,6 @@ namespace k8s.Tests.Logging /// public TestOutputLogger(ITestOutputHelper testOutput, string loggerCategory, LogLevel minLogLevel) { - if (testOutput == null) - { - throw new ArgumentNullException(nameof(testOutput)); - } - if (string.IsNullOrWhiteSpace(loggerCategory)) { throw new ArgumentException( @@ -38,7 +33,7 @@ namespace k8s.Tests.Logging nameof(loggerCategory)); } - TestOutput = testOutput; + TestOutput = testOutput ?? throw new ArgumentNullException(nameof(testOutput)); LoggerCategory = loggerCategory; MinLogLevel = minLogLevel; } @@ -61,6 +56,7 @@ namespace k8s.Tests.Logging /// /// Emit a log entry. /// + /// Type of state to log. /// /// The log entry's level. /// @@ -124,6 +120,7 @@ namespace k8s.Tests.Logging /// /// Begin a logical operation scope. /// + /// Type of state to log. /// /// An identifier for the scope. /// diff --git a/tests/KubernetesClient.Tests/Mock/MockKubeApiServer.cs b/tests/KubernetesClient.Tests/Mock/MockKubeApiServer.cs index 5e4f9b8..67a1bd7 100644 --- a/tests/KubernetesClient.Tests/Mock/MockKubeApiServer.cs +++ b/tests/KubernetesClient.Tests/Mock/MockKubeApiServer.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using System.Net; -using System.Threading.Tasks; using k8s.Tests.Logging; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; @@ -10,6 +6,10 @@ using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Logging; +using System; +using System.Linq; +using System.Net; +using System.Threading.Tasks; using Xunit.Abstractions; namespace k8s.Tests.Mock diff --git a/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs b/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs index 1310079..d908a46 100644 --- a/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs +++ b/tests/KubernetesClient.Tests/Mock/MockWebSocket.cs @@ -12,9 +12,9 @@ namespace k8s.Tests.Mock private WebSocketCloseStatus? closeStatus; private string closeStatusDescription; private WebSocketState state; - private string subProtocol; - private ConcurrentQueue receiveBuffers = new ConcurrentQueue(); - private AsyncAutoResetEvent receiveEvent = new AsyncAutoResetEvent(false); + private readonly string subProtocol; + private readonly ConcurrentQueue receiveBuffers = new ConcurrentQueue(); + private readonly AsyncAutoResetEvent receiveEvent = new AsyncAutoResetEvent(false); private bool disposedValue; public MockWebSocket(string subProtocol = null) diff --git a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs index 65800f3..d907d29 100644 --- a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs +++ b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodExecController.cs @@ -20,12 +20,7 @@ namespace k8s.Tests.Mock.Server.Controllers /// public PodExecController(WebSocketTestAdapter webSocketTestAdapter) { - if (webSocketTestAdapter == null) - { - throw new ArgumentNullException(nameof(webSocketTestAdapter)); - } - - WebSocketTestAdapter = webSocketTestAdapter; + WebSocketTestAdapter = webSocketTestAdapter ?? throw new ArgumentNullException(nameof(webSocketTestAdapter)); } /// @@ -42,8 +37,7 @@ namespace k8s.Tests.Mock.Server.Controllers /// /// The target pod's name. /// - /// A representing the asynchronous operation. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. [Route("namespaces/{kubeNamespace}/pods/{podName}/exec")] public async Task Exec(string kubeNamespace, string podName) { diff --git a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs index 0780c8b..d05f0ca 100644 --- a/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs +++ b/tests/KubernetesClient.Tests/Mock/Server/Controllers/PodPortForwardController.cs @@ -21,12 +21,7 @@ namespace k8s.Tests.Mock.Server.Controllers /// public PodPortForwardController(WebSocketTestAdapter webSocketTestAdapter) { - if (webSocketTestAdapter == null) - { - throw new ArgumentNullException(nameof(webSocketTestAdapter)); - } - - WebSocketTestAdapter = webSocketTestAdapter; + WebSocketTestAdapter = webSocketTestAdapter ?? throw new ArgumentNullException(nameof(webSocketTestAdapter)); } /// @@ -46,8 +41,7 @@ namespace k8s.Tests.Mock.Server.Controllers /// /// The port(s) to forward to the pod. /// - /// A representing the asynchronous operation. - /// A representing the asynchronous operation. + /// A representing the asynchronous operation. [Route("namespaces/{kubeNamespace}/pods/{podName}/portforward")] public async Task Exec(string kubeNamespace, string podName, IEnumerable ports) { diff --git a/tests/KubernetesClient.Tests/ModelExtensionTests.cs b/tests/KubernetesClient.Tests/ModelExtensionTests.cs index 59e5490..83037a6 100644 --- a/tests/KubernetesClient.Tests/ModelExtensionTests.cs +++ b/tests/KubernetesClient.Tests/ModelExtensionTests.cs @@ -1,5 +1,5 @@ -using System; using k8s.Models; +using System; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/OidcAuthTests.cs b/tests/KubernetesClient.Tests/OidcAuthTests.cs index db9c367..9889c3f 100644 --- a/tests/KubernetesClient.Tests/OidcAuthTests.cs +++ b/tests/KubernetesClient.Tests/OidcAuthTests.cs @@ -1,8 +1,8 @@ -using System.Threading; -using System.Threading.Tasks; using FluentAssertions; using k8s.Authentication; using k8s.Exceptions; +using System.Threading; +using System.Threading.Tasks; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/OperatingSystems.cs b/tests/KubernetesClient.Tests/OperatingSystems.cs index e596619..73c96cc 100644 --- a/tests/KubernetesClient.Tests/OperatingSystems.cs +++ b/tests/KubernetesClient.Tests/OperatingSystems.cs @@ -5,8 +5,13 @@ namespace k8s.Tests [Flags] public enum OperatingSystems { + /// Windows operating system. Windows = 1, + + /// Linux operating system. Linux = 2, + + /// OSX operating system. OSX = 4, } } diff --git a/tests/KubernetesClient.Tests/PodExecTests.cs b/tests/KubernetesClient.Tests/PodExecTests.cs index 4949860..067060c 100644 --- a/tests/KubernetesClient.Tests/PodExecTests.cs +++ b/tests/KubernetesClient.Tests/PodExecTests.cs @@ -2,8 +2,8 @@ * These tests are for the netcoreapp2.1 version of the client (there are separate tests for netstandard that don't actually connect to a server). */ -using k8s.Models; using k8s.Autorest; +using k8s.Models; using System; using System.Collections.Generic; using System.Diagnostics; @@ -42,8 +42,7 @@ namespace k8s.Tests /// /// Verify that the client can request execution of a command in a pod's default container, with only the STDOUT stream enabled. /// - /// A representing the asynchronous unit test. - /// A representing the asynchronous unit test. + /// A representing the asynchronous unit test. [Fact(DisplayName = "Can exec in pod's default container, STDOUT only")] public async Task ExecDefaultContainerStdOut() { diff --git a/tests/KubernetesClient.Tests/QuantityValueTests.cs b/tests/KubernetesClient.Tests/QuantityValueTests.cs index 8b61fe6..ede6ce7 100644 --- a/tests/KubernetesClient.Tests/QuantityValueTests.cs +++ b/tests/KubernetesClient.Tests/QuantityValueTests.cs @@ -1,5 +1,5 @@ -using System; using k8s.Models; +using System; using Xunit; using static k8s.Models.ResourceQuantity.SuffixFormat; diff --git a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs index 926857e..03d9981 100644 --- a/tests/KubernetesClient.Tests/StreamDemuxerTests.cs +++ b/tests/KubernetesClient.Tests/StreamDemuxerTests.cs @@ -1,10 +1,10 @@ +using k8s.Tests.Mock; using System; using System.Collections.Generic; using System.Diagnostics; using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using k8s.Tests.Mock; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/TokenFileAuthTests.cs b/tests/KubernetesClient.Tests/TokenFileAuthTests.cs index c31eb89..9d3be6b 100644 --- a/tests/KubernetesClient.Tests/TokenFileAuthTests.cs +++ b/tests/KubernetesClient.Tests/TokenFileAuthTests.cs @@ -1,8 +1,8 @@ +using FluentAssertions; +using k8s.Authentication; using System; using System.Threading; using System.Threading.Tasks; -using FluentAssertions; -using k8s.Authentication; using Xunit; namespace k8s.Tests diff --git a/tests/KubernetesClient.Tests/VersionConverterTests.cs b/tests/KubernetesClient.Tests/VersionConverterTests.cs index 269beea..bb1b495 100644 --- a/tests/KubernetesClient.Tests/VersionConverterTests.cs +++ b/tests/KubernetesClient.Tests/VersionConverterTests.cs @@ -1,7 +1,7 @@ -using Xunit; +using AutoMapper; using FluentAssertions; using k8s.Versioning; -using AutoMapper; +using Xunit; namespace k8s.Tests { diff --git a/tests/KubernetesClient.Tests/WatchTests.cs b/tests/KubernetesClient.Tests/WatchTests.cs index b5d92b2..bddf0c2 100644 --- a/tests/KubernetesClient.Tests/WatchTests.cs +++ b/tests/KubernetesClient.Tests/WatchTests.cs @@ -1,3 +1,7 @@ +using k8s.Models; +using k8s.Tests.Mock; +using Microsoft.AspNetCore.Http; +using Nito.AsyncEx; using System; using System.Collections.Generic; using System.IO; @@ -7,10 +11,6 @@ using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; -using k8s.Models; -using k8s.Tests.Mock; -using Microsoft.AspNetCore.Http; -using Nito.AsyncEx; using Xunit; using Xunit.Abstractions; diff --git a/tests/KubernetesClient.Tests/WebSocketTestBase.cs b/tests/KubernetesClient.Tests/WebSocketTestBase.cs index bbf2b6f..15c9205 100644 --- a/tests/KubernetesClient.Tests/WebSocketTestBase.cs +++ b/tests/KubernetesClient.Tests/WebSocketTestBase.cs @@ -1,10 +1,10 @@ +using k8s.Autorest; using k8s.Tests.Logging; using k8s.Tests.Mock.Server; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using k8s.Autorest; using System; using System.IO; using System.Net.WebSockets; @@ -107,7 +107,7 @@ namespace k8s.Tests /// /// Configure logging for the test server. /// - /// + /// /// The logger factory to configure. /// protected virtual void ConfigureTestServerLogging(ILoggingBuilder logging) @@ -276,9 +276,6 @@ namespace k8s.Tests /// /// The target . /// - /// - /// The text to send. - /// /// /// A tuple containing the received text, 0-based substream index, and total bytes received. /// diff --git a/tests/SkipTestLogger/SkipTestLogger.cs b/tests/SkipTestLogger/SkipTestLogger.cs index 5cf094b..7e33b80 100644 --- a/tests/SkipTestLogger/SkipTestLogger.cs +++ b/tests/SkipTestLogger/SkipTestLogger.cs @@ -1,8 +1,8 @@ +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using System; using System.Collections.Generic; using System.IO; -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; namespace k8s.E2E {