From 746b079091b1a85318f951229303dc1a1c1da300 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 18 Sep 2023 22:11:28 +0200 Subject: [PATCH] test fixes --- .../CosmosDbConformanceTests.cs | 15 ++----- .../HealthChecks.CosmosDb.Tests.csproj | 1 - .../HealthChecks.CosmosDb.approved.txt | 42 +++---------------- 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/test/HealthChecks.CosmosDb.Tests/CosmosDbConformanceTests.cs b/test/HealthChecks.CosmosDb.Tests/CosmosDbConformanceTests.cs index e35983f1bb..452d56489f 100644 --- a/test/HealthChecks.CosmosDb.Tests/CosmosDbConformanceTests.cs +++ b/test/HealthChecks.CosmosDb.Tests/CosmosDbConformanceTests.cs @@ -1,24 +1,17 @@ -using Azure.Identity; using Microsoft.Azure.Cosmos; namespace HealthChecks.CosmosDb.Tests; public class CosmosDbConformanceTests : ConformanceTests { + // Sample raw connection string taken from https://github.com/Azure/azure-cosmos-dotnet-v3/blob/258d960ae3caa3ad989f60d5e656544c35006d0a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientTests.cs#L34 + private const string ConnectionString = "AccountEndpoint=https://localtestcosmos.documents.azure.com:443/;AccountKey=425Mcv8CXQqzRNCgFNjIhT424GK99CKJvASowTnq15Vt8LeahXTcN5wt3342vQ==;"; + protected override IHealthChecksBuilder AddHealthCheck(IHealthChecksBuilder builder, Func? clientFactory = null, Func? optionsFactory = null, string? healthCheckName = null, HealthStatus? failureStatus = null, IEnumerable? tags = null, TimeSpan? timeout = null) => builder.AddAzureCosmosDB(clientFactory, optionsFactory, healthCheckName, failureStatus, tags, timeout); protected override CosmosClient CreateClientForNonExistingEndpoint() - => new CosmosClient( - "https://www.thisisnotarealurl.com", - new DefaultAzureCredential(), - new CosmosClientOptions() - { - RequestTimeout = TimeSpan.FromMilliseconds(10), - MaxRetryAttemptsOnRateLimitedRequests = 0, - MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.Zero, - ApplicationRegion = Regions.EastUS2, - }); + => new(ConnectionString); protected override AzureCosmosDbHealthCheck CreateHealthCheck(CosmosClient client, AzureCosmosDbHealthCheckOptions? options) => new(client, options); diff --git a/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.Tests.csproj b/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.Tests.csproj index d3390eda18..fd3a8e20bb 100644 --- a/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.Tests.csproj +++ b/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.Tests.csproj @@ -5,7 +5,6 @@ - diff --git a/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.approved.txt b/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.approved.txt index fb538e16cb..a2e98ea3ce 100644 --- a/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.approved.txt +++ b/test/HealthChecks.CosmosDb.Tests/HealthChecks.CosmosDb.approved.txt @@ -1,53 +1,21 @@ namespace HealthChecks.CosmosDb { - public class CosmosDbHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck + public sealed class AzureCosmosDbHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck { - public CosmosDbHealthCheck(Microsoft.Azure.Cosmos.CosmosClient cosmosClient) { } - public CosmosDbHealthCheck(string connectionString) { } - public CosmosDbHealthCheck(Microsoft.Azure.Cosmos.CosmosClient cosmosClient, HealthChecks.CosmosDb.CosmosDbHealthCheckOptions options) { } - public CosmosDbHealthCheck(string connectionString, string database) { } - public CosmosDbHealthCheck(string accountEndpoint, Azure.Core.TokenCredential tokenCredential, string database) { } - public CosmosDbHealthCheck(string connectionString, string? database, System.Collections.Generic.IEnumerable? containers) { } - public CosmosDbHealthCheck(string accountEndpoint, Azure.Core.TokenCredential tokenCredential, string? database, System.Collections.Generic.IEnumerable? containers) { } + public AzureCosmosDbHealthCheck(Microsoft.Azure.Cosmos.CosmosClient cosmosClient, HealthChecks.CosmosDb.AzureCosmosDbHealthCheckOptions? options) { } public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } } - public sealed class CosmosDbHealthCheckOptions + public sealed class AzureCosmosDbHealthCheckOptions { - public CosmosDbHealthCheckOptions() { } + public AzureCosmosDbHealthCheckOptions() { } public System.Collections.Generic.IEnumerable? ContainerIds { get; set; } public string? DatabaseId { get; set; } } - public class TableServiceHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck - { - public TableServiceHealthCheck(Azure.Data.Tables.TableServiceClient tableServiceClient, HealthChecks.CosmosDb.TableServiceHealthCheckOptions options) { } - public TableServiceHealthCheck(string connectionString, string? tableName) { } - public TableServiceHealthCheck(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, string? tableName) { } - public TableServiceHealthCheck(System.Uri endpoint, Azure.Data.Tables.TableSharedKeyCredential credentials, string? tableName) { } - public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } - } - public sealed class TableServiceHealthCheckOptions - { - public TableServiceHealthCheckOptions() { } - public string? TableName { get; set; } - } } namespace Microsoft.Extensions.DependencyInjection { public static class CosmosDbHealthCheckBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? configureOptions = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? configureOptions = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string connectionString, string tableName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, string tableName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Uri endpoint, Azure.Data.Tables.TableSharedKeyCredential credentials, string? tableName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, Microsoft.Azure.Cosmos.CosmosClient client, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? configureOptions = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Action? configureOptions = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, Microsoft.Azure.Cosmos.CosmosClient client, System.Action configureOptions, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, Microsoft.Azure.Cosmos.CosmosClient client, System.Action configureOptions, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string connectionString, string? database = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string accountEndpoint, Azure.Core.TokenCredential tokenCredential, string? database = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDbCollection(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string connectionString, string? database = null, System.Collections.Generic.IEnumerable? collections = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddCosmosDbCollection(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string accountEndpoint, Azure.Core.TokenCredential tokenCredential, string? database = null, System.Collections.Generic.IEnumerable? collections = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureCosmosDB(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_cosmosdb", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } \ No newline at end of file