From cce5624abe5362725d1ed46689aee46f7efd4774 Mon Sep 17 00:00:00 2001 From: Daouda Diakite Date: Wed, 6 Nov 2024 09:29:48 +0100 Subject: [PATCH] Using configuration object to read options --- .../ArmoniK.Api.Client.Test/ConfTest.cs | 22 +- .../EventsClientTest.cs | 37 +-- .../HealthCheckTest.cs | 39 +-- .../PartitionClientTest.cs | 47 +--- .../ResultsClientTest.cs | 121 +------- .../SessionClientTest.cs | 125 +-------- .../SubmitterClientTest.cs | 259 ++++-------------- .../TasksClientTest.cs | 107 +------- .../VersionClientTest.cs | 39 +-- 9 files changed, 118 insertions(+), 678 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Client.Test/ConfTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/ConfTest.cs index e2663249c..feee8d14f 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/ConfTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/ConfTest.cs @@ -25,15 +25,15 @@ using System; using System.IO; using System.Net.Http; -using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; - -using Microsoft.Extensions.Configuration; +using System.Threading.Tasks; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; +using Microsoft.Extensions.Configuration; + using Newtonsoft.Json.Linq; using Org.BouncyCastle.X509; @@ -49,11 +49,11 @@ public static GrpcClient GetChannelOptions() var builder = new ConfigurationBuilder().AddEnvironmentVariables(); var configuration = builder.Build(); var options = configuration.GetRequiredSection(GrpcClient.SettingSection) - .Get(); + .Get(); if (options!.AllowUnsafeConnection) { if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || options.HttpMessageHandler.ToLower() - .Contains("web")) + .Contains("web")) { options!.Endpoint = Environment.GetEnvironmentVariable("Http__Endpoint"); } @@ -63,9 +63,9 @@ public static GrpcClient GetChannelOptions() } public static async Task RpcCalled(string service_name, - string rpc_name) + string rpc_name) { - var options = GetChannelOptions(); + var options = GetChannelOptions(); X509Certificate? caCert = null; if (!string.IsNullOrWhiteSpace(options.CaCert) && !options.AllowUnsafeConnection) @@ -92,6 +92,7 @@ public static async Task RpcCalled(string service_name, { handler.ClientCertificates.Add(clientCert!); } + handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, certChain, @@ -111,10 +112,11 @@ public static async Task RpcCalled(string service_name, var call_endpoint = Environment.GetEnvironmentVariable("Http__Endpoint") + "/calls.json"; try { - using HttpResponseMessage response = await client.GetAsync(call_endpoint); + using var response = await client.GetAsync(call_endpoint); response.EnsureSuccessStatusCode(); - string responseBody = response.Content.ReadAsStringAsync().Result; - JObject jsonResponse = JObject.Parse(responseBody); + var responseBody = response.Content.ReadAsStringAsync() + .Result; + var jsonResponse = JObject.Parse(responseBody); return (uint)jsonResponse[service_name][rpc_name]; } catch (HttpRequestException e) diff --git a/packages/csharp/ArmoniK.Api.Client.Test/EventsClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/EventsClientTest.cs index 1a762986c..66c412172 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/EventsClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/EventsClientTest.cs @@ -23,8 +23,6 @@ // along with this program. If not, see . using System; -using System.Linq; -using System.Runtime.InteropServices; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -48,28 +46,9 @@ public class EventsClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient options_; [Test] public void TestGetEvents() @@ -78,15 +57,7 @@ public void TestGetEvents() "GetEvents") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_); var partition = "default"; var taskOptions = new TaskOptions { @@ -149,6 +120,6 @@ public void TestGetEvents() .GetAwaiter() .GetResult(); Assert.AreEqual(after - before, - 0); + 1); } } diff --git a/packages/csharp/ArmoniK.Api.Client.Test/HealthCheckTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/HealthCheckTest.cs index 4fabd9439..68ace78fb 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/HealthCheckTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/HealthCheckTest.cs @@ -22,9 +22,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -using System; -using System.Runtime.InteropServices; - using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; using ArmoniK.Api.gRPC.V1.HealthChecks; @@ -38,29 +35,9 @@ public class HealthCheckTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestHealthCheck() @@ -69,16 +46,8 @@ public void TestHealthCheck() "CheckHealth") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new HealthChecksService.HealthChecksServiceClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new HealthChecksService.HealthChecksServiceClient(channel); Assert.That(() => client.CheckHealth(new CheckHealthRequest()), Throws.Nothing); var after = ConfTest.RpcCalled("HealthChecks", diff --git a/packages/csharp/ArmoniK.Api.Client.Test/PartitionClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/PartitionClientTest.cs index 376f60b6b..e2f454d09 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/PartitionClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/PartitionClientTest.cs @@ -23,7 +23,6 @@ // along with this program. If not, see . using System; -using System.Runtime.InteropServices; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -41,29 +40,9 @@ public class PartitionClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestGetPartition() @@ -72,15 +51,7 @@ public void TestGetPartition() "GetPartition") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var taskOptions = new TaskOptions { @@ -112,16 +83,8 @@ public void TestListPartitions() "ListPartitions") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Partitions.PartitionsClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Partitions.PartitionsClient(channel); Assert.That(() => client.ListPartitions(new ListPartitionsRequest { diff --git a/packages/csharp/ArmoniK.Api.Client.Test/ResultsClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/ResultsClientTest.cs index 35766d87f..8a0d703a2 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/ResultsClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/ResultsClientTest.cs @@ -25,7 +25,6 @@ using System; using System.Text; using System.Threading; -using System.Runtime.InteropServices; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -48,29 +47,9 @@ public class ResultsClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestGetResult() @@ -79,16 +58,8 @@ public void TestGetResult() "GetResult") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Results.ResultsClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Results.ResultsClient(channel); Assert.That(() => client.GetResult(new GetResultRequest { ResultId = "result-name", @@ -109,15 +80,7 @@ public void TestGetOwnerTaskId() "GetOwnerTaskId") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -159,15 +122,7 @@ public void TestCreateResultMetaData() "CreateResultsMetaData") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -212,15 +167,7 @@ public void TestCreateResult() "CreateResults") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -265,16 +212,8 @@ public void TestListResults() "ListResults") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Results.ResultsClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Results.ResultsClient(channel); Assert.That(() => client.ListResults(new ListResultsRequest { Filters = new Filters @@ -321,15 +260,7 @@ public void TestUploadResults() "UploadResultData") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -367,15 +298,7 @@ public void TestDownloadResults() "DownloadResultData") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -412,15 +335,7 @@ public void TestDeleteResults() "DeleteResultsData") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Results.ResultsClient(channel); var taskOptions = new TaskOptions @@ -462,16 +377,8 @@ public void TestWatchResults() "WatchResults") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Results.ResultsClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Results.ResultsClient(channel); Assert.That(() => client.WatchResults(), Throws.Nothing); var after = ConfTest.RpcCalled("Results", diff --git a/packages/csharp/ArmoniK.Api.Client.Test/SessionClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/SessionClientTest.cs index ae20b1179..118af5ebf 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/SessionClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/SessionClientTest.cs @@ -23,7 +23,6 @@ // along with this program. If not, see . using System; -using System.Runtime.InteropServices; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -41,29 +40,9 @@ public class SessionClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => option_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? option_; [Test] public void TestCreateSession() @@ -72,15 +51,7 @@ public void TestCreateSession() "CreateSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -115,15 +86,7 @@ public void TestCancelSession() "CancelSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -162,15 +125,7 @@ public void TestGetSession() "GetSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -209,15 +164,7 @@ public void TestListSessions() "ListSessions") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -260,15 +207,7 @@ public void TestPauseSession() "PauseSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -307,15 +246,7 @@ public void TestResumeSession() "ResumeSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -358,15 +289,7 @@ public void TestPurgeSession() "PurgeSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -410,15 +333,7 @@ public void TestDeleteSession() "DeleteSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -457,15 +372,7 @@ public void TestStopSubmission() "StopSubmission") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions @@ -504,15 +411,7 @@ public void TestCloseSession() "CloseSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(option_!); var partition = "default"; var client = new Sessions.SessionsClient(channel); var taskOptions = new TaskOptions diff --git a/packages/csharp/ArmoniK.Api.Client.Test/SubmitterClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/SubmitterClientTest.cs index be3251265..97eb36714 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/SubmitterClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/SubmitterClientTest.cs @@ -24,13 +24,12 @@ using System; using System.Linq; -using System.Runtime.InteropServices; using System.Threading; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; -using ArmoniK.Api.gRPC.V1.Submitter; using ArmoniK.Api.gRPC.V1; +using ArmoniK.Api.gRPC.V1.Submitter; using Google.Protobuf.WellKnownTypes; @@ -45,55 +44,27 @@ public class SubmitterClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestGetServiceConfiguration() { var before = ConfTest.RpcCalled("Submitter", - "GetServiceConfiguration") - .GetAwaiter() - .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); - Assert.That(() => client.GetServiceConfiguration(new Empty()), - Throws.Nothing); - var after = ConfTest.RpcCalled("Submitter", "GetServiceConfiguration") .GetAwaiter() .GetResult(); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + Assert.That(() => client.GetServiceConfiguration(new Empty()), + Throws.Nothing); + var after = ConfTest.RpcCalled("Submitter", + "GetServiceConfiguration") + .GetAwaiter() + .GetResult(); Assert.AreEqual(after - before, - 1); + 1); } [Test] @@ -103,15 +74,7 @@ public void TestCreateSession() "CreateSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); var taskOptions = new TaskOptions @@ -145,16 +108,8 @@ public void TestCancelSession() "CancelSession") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.CancelSession(new Session { Id = "session-id", @@ -175,15 +130,7 @@ public void TestCreateSmallTasks() "CreateSmallTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); var taskOptions = new TaskOptions @@ -197,9 +144,6 @@ public void TestCreateSmallTasks() { SessionId = "session-id", TaskOptions = taskOptions, - TaskRequests = - { - }, }), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", @@ -217,15 +161,7 @@ public void TestCreateLargeTasks() "CreateLargeTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); var taskOptions = new TaskOptions @@ -235,11 +171,10 @@ public void TestCreateLargeTasks() Priority = 1, PartitionId = partition, }; - Assert.That(() => SubmitterClientExt.CreateTasksAsync(client, - "session-id", - taskOptions, - Enumerable.Empty(), - CancellationToken.None), + Assert.That(() => client.CreateTasksAsync("session-id", + taskOptions, + Enumerable.Empty(), + CancellationToken.None), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", "CreateLargeTasks") @@ -256,19 +191,9 @@ public void TestListTasks() "ListTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); - Assert.That(() => client.ListTasks(new TaskFilter - { - }), + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + Assert.That(() => client.ListTasks(new TaskFilter()), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", "ListTasks") @@ -285,19 +210,9 @@ public void TestListSessions() "ListSessions") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); - Assert.That(() => client.ListSessions(new SessionFilter - { - }), + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + Assert.That(() => client.ListSessions(new SessionFilter()), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", "ListSessions") @@ -314,19 +229,9 @@ public void TestCountTasks() "CountTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); - Assert.That(() => client.CountTasks(new TaskFilter - { - }), + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + Assert.That(() => client.CountTasks(new TaskFilter()), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", "CountTasks") @@ -343,16 +248,8 @@ public void TestTryGetResult() "TryGetResultStream") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.TryGetResultStream(new ResultRequest { ResultId = "result-id", @@ -374,16 +271,8 @@ public void TestTryGetTaskOutput() "TryGetTaskOutput") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.TryGetTaskOutput(new TaskOutputRequest { Session = "session-id", @@ -405,16 +294,8 @@ public void TestWaitForAvailability() "WaitForAvailability") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.WaitForAvailability(new ResultRequest { ResultId = "result-id", @@ -436,21 +317,11 @@ public void TestWaitForCompletion() "WaitForCompletion") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.WaitForCompletion(new WaitRequest { - Filter = new TaskFilter - { - }, + Filter = new TaskFilter(), StopOnFirstTaskError = true, StopOnFirstTaskCancellation = true, }), @@ -470,19 +341,9 @@ public void TestCancelTasks() "CancelTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); - Assert.That(() => client.CancelTasks(new TaskFilter - { - }), + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + Assert.That(() => client.CancelTasks(new TaskFilter()), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", "CancelTasks") @@ -499,16 +360,8 @@ public void TestTaskStatus() "GetTaskStatus") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.GetTaskStatus(new GetTaskStatusRequest { TaskIds = @@ -532,16 +385,8 @@ public void TestResultStatus() "GetResultStatus") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.GetResultStatus(new GetResultStatusRequest { SessionId = "session-id", @@ -566,16 +411,8 @@ public void TestWatchResults() "WatchResults") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new gRPC.V1.Submitter.Submitter.SubmitterClient(channel); Assert.That(() => client.WatchResults(), Throws.Nothing); var after = ConfTest.RpcCalled("Submitter", diff --git a/packages/csharp/ArmoniK.Api.Client.Test/TasksClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/TasksClientTest.cs index e26ce2baa..b31c73e89 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/TasksClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/TasksClientTest.cs @@ -23,7 +23,6 @@ // along with this program. If not, see . using System; -using System.Runtime.InteropServices; using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -44,6 +43,10 @@ namespace ArmoniK.Api.Client.Tests; [TestFixture] public class TasksClientTest { + [SetUp] + public void SetUp() + => options_ = ConfTest.GetChannelOptions(); + private static FiltersAnd TasksFilter(string sessionId) => new() { @@ -67,31 +70,7 @@ private static FiltersAnd TasksFilter(string sessionId) }, }; - [SetUp] - public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } - - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestSubmitTask() @@ -100,15 +79,7 @@ public void TestSubmitTask() "SubmitTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Tasks.TasksClient(channel); var taskOptions = new TaskOptions @@ -157,15 +128,7 @@ public void TestCountTask() "CountTasksByStatus") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Tasks.TasksClient(channel); var taskOptions = new TaskOptions @@ -209,16 +172,8 @@ public void TestGetResultsIds() "GetResultIds") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Tasks.TasksClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Tasks.TasksClient(channel); Assert.That(() => client.GetResultIds(new GetResultIdsRequest { TaskId = @@ -242,16 +197,8 @@ public void TestGetTask() "GetTask") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Tasks.TasksClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Tasks.TasksClient(channel); Assert.That(() => client.GetTask(new GetTaskRequest { TaskId = "task-id", @@ -272,16 +219,8 @@ public void TestCancelTask() "CancelTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Tasks.TasksClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Tasks.TasksClient(channel); Assert.AreNotEqual(client.GetTask(new GetTaskRequest { TaskId = "task-id", @@ -311,15 +250,7 @@ public void TestListTasks() "ListTasks") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Tasks.TasksClient(channel); var taskOptions = new TaskOptions @@ -363,15 +294,7 @@ public void TestListTaskDetailed() "ListTasksDetailed") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); + var channel = GrpcChannelFactory.CreateChannel(options_!); var partition = "default"; var client = new Tasks.TasksClient(channel); var taskOptions = new TaskOptions diff --git a/packages/csharp/ArmoniK.Api.Client.Test/VersionClientTest.cs b/packages/csharp/ArmoniK.Api.Client.Test/VersionClientTest.cs index 58623aa4e..56bad9771 100644 --- a/packages/csharp/ArmoniK.Api.Client.Test/VersionClientTest.cs +++ b/packages/csharp/ArmoniK.Api.Client.Test/VersionClientTest.cs @@ -22,9 +22,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -using System; -using System.Runtime.InteropServices; - using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; using ArmoniK.Api.gRPC.V1.Versions; @@ -38,29 +35,9 @@ public class VersionClientTest { [SetUp] public void SetUp() - { - certPath_ = Environment.GetEnvironmentVariable("Grpc__ClientCert") ?? ""; - keyPath_ = Environment.GetEnvironmentVariable("Grpc__ClientKey") ?? ""; - CaCertPath_ = Environment.GetEnvironmentVariable("Grpc__CaCert") ?? ""; - MessageHandler_ = Environment.GetEnvironmentVariable("GrpcClient__HttpMessageHandler") ?? ""; - endpoint_ = Environment.GetEnvironmentVariable("Grpc__Endpoint") ?? ""; - isInsecure_ = Environment.GetEnvironmentVariable("Grpc__AllowUnsafeConnection") == "true"; - - if (isInsecure_) - { - endpoint_ = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") || MessageHandler_.ToLower() - .Contains("web") - ? "http://localhost:4999" - : endpoint_; - } - } + => options_ = ConfTest.GetChannelOptions(); - private static string? endpoint_; - private static string? certPath_; - private static string? keyPath_; - private static string? CaCertPath_; - private static string? MessageHandler_; - private bool isInsecure_; + private GrpcClient? options_; [Test] public void TestListVersions() @@ -69,16 +46,8 @@ public void TestListVersions() "ListVersions") .GetAwaiter() .GetResult(); - var channel = GrpcChannelFactory.CreateChannel(new GrpcClient - { - Endpoint = endpoint_, - AllowUnsafeConnection = isInsecure_, - CertPem = certPath_!, - KeyPem = keyPath_!, - CaCert = CaCertPath_!, - HttpMessageHandler = MessageHandler_!, - }); - var client = new Versions.VersionsClient(channel); + var channel = GrpcChannelFactory.CreateChannel(options_!); + var client = new Versions.VersionsClient(channel); Assert.That(() => client.ListVersions(new ListVersionsRequest()), Throws.Nothing);