Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API approval tests, more implicit usings, add NRT annotations, cleanup whitespaces #1175

Merged
merged 2 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/healthchecks_elasticsearch_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
tags:
- release-elasticsearch-* # Push events to release-elasticsearch*


jobs:
build:
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
tags:
- preview-elasticsearch-* # Push events to release-elasticsearch*


jobs:
build:
env:
Expand Down
17 changes: 17 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,39 @@
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<None Include="..\..\assets\icon.png" Pack="true" PackagePath="\" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<Compile Include="../ApiMarker.cs" Link="ApiMarker.cs" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('.Tests')) OR $(MSBuildProjectName) == 'UnitTests'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.5" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="PublicApiGenerator" Version="10.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<ProjectReference Include="..\..\src\HealthChecks.UI.Client\HealthChecks.UI.Client.csproj" />

<Compile Include="../ApiApprovalTests.cs" Link="ApiApprovalTests.cs" />

<Using Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" />
<Using Include="Microsoft.AspNetCore.Hosting" />
<Using Include="Microsoft.AspNetCore.Builder" />
<Using Include="Microsoft.AspNetCore.TestHost" />
<Using Include="Microsoft.Extensions.DependencyInjection" />
<Using Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<Using Include="Microsoft.Extensions.Options" />
<Using Include="FluentAssertions" />
<Using Include="Shouldly" />
<Using Include="Xunit" />
</ItemGroup>

</Project>
2 changes: 0 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ finally {
Pop-Location
}


if (-Not (Test-Path 'env:APPVEYOR')) {
exec { & docker-compose up -d }
}
Expand All @@ -66,7 +65,6 @@ finally {
Pop-Location
}


if ($suffix -eq "") {
exec { & dotnet pack .\src\HealthChecks.SqlServer\HealthChecks.SqlServer.csproj -c Release -o .\artifacts --include-symbols --no-build }
exec { & dotnet pack .\src\HealthChecks.Redis\HealthChecks.Redis.csproj -c Release -o .\artifacts --include-symbols --no-build }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public static bool Enabled
EnvironmentVariable.HasValue(AzureAppConfigurationKeys.CacheExpiration)
&& double.TryParse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration), out var _);

public static double CacheExpiration => double.Parse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration));
public static double CacheExpiration => double.Parse(EnvironmentVariable.GetValue(AzureAppConfigurationKeys.CacheExpiration)!);

public static string ConnectionString =>
public static string? ConnectionString =>
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ConnectionString);

public static string ManagedIdentityEndpoint =>
public static string? ManagedIdentityEndpoint =>
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.ManagedIdentityEndpoint);

public static string Label =>
public static string? Label =>
EnvironmentVariable.GetValue(AzureAppConfigurationKeys.Label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace HealthChecks.UI.Image.Configuration.Helpers
{
public class EnvironmentVariable
{
public static string GetValue(string variable) =>
public static string? GetValue(string variable) =>
Environment.GetEnvironmentVariable(variable);

public static bool HasValue(string variable) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class StorageProvider
{
public bool RequiresConnectionString { get; set; }
public Action<HealthChecksUIBuilder, string> SetupProvider { get; set; }
= (_, connection) => throw new InvalidOperationException($"Misconfigured storage provider for {connection}");
}

public enum StorageProviderEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class HealthChecksUIBuilderExtensions
{

public static IServiceCollection AddStorageProvider(this HealthChecksUIBuilder builder, IConfiguration configuration)
{
string configuredStorage = configuration[UIKeys.STORAGE_PROVIDER];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static IConfigurationBuilder UseAzureAppConfiguration(this IConfiguration
Action<AzureAppConfigurationOptions> setupConfig = AzureAppConfiguration.UseConnectionString switch
{
true => options => options.Connect(AzureAppConfiguration.ConnectionString),
false => options => options.Connect(new Uri(AzureAppConfiguration.ManagedIdentityEndpoint), new ManagedIdentityCredential())
false => options => options.Connect(new Uri(AzureAppConfiguration.ManagedIdentityEndpoint!), new ManagedIdentityCredential())
};

builder.AddAzureAppConfiguration(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IEndpointConventionBuilder MapHealthChecksUI(this IEndpointRouteBu
{
if (bool.TryParse(configuration[PushServiceKeys.Enabled], out bool enabled) && enabled)
{
builder.MapHealthCheckPushEndpoint(configuration);
builder.MapHealthCheckPushEndpoint(/*configuration*/);
}

return builder.MapHealthChecksUI(setup =>
Expand All @@ -23,10 +23,8 @@ public static IEndpointConventionBuilder MapHealthChecksUI(this IEndpointRouteBu

});
}
private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builder,
IConfiguration configuration)
private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builder/*, IConfiguration configuration*/)
{

var logger = builder.ServiceProvider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("HealthChecks Push Endpoint Enabled");

Expand All @@ -45,7 +43,7 @@ private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builde

if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(uri))
{
var pushService = context.RequestServices.GetService<HealthChecksPushService>();
var pushService = context.RequestServices.GetRequiredService<HealthChecksPushService>();

if (type == PushServiceKeys.ServiceAdded)
{
Expand All @@ -65,7 +63,6 @@ private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builde
{
context.Response.StatusCode = 401;
}

});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task UpdateAsync(string name, string uri)
}
}

private Task<HealthCheckConfiguration> Get(string name)
private Task<HealthCheckConfiguration?> Get(string name)
{
return _db.Configurations.FirstOrDefaultAsync(c => c.Name == name);
}
Expand Down
2 changes: 0 additions & 2 deletions dotnet-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ function GetHTTPResponse([Uri] $Uri)
})
}


function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Coherent) {
Say-Invocation $MyInvocation

Expand Down Expand Up @@ -286,7 +285,6 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co
return $VersionInfo
}


function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$Version) {
Say-Invocation $MyInvocation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace HealthChecks.UIAndApi.Options
{
public class RemoteOptions
{
public Uri RemoteDependency { get; set; }
public Uri RemoteDependency { get; set; } = null!;
}
}
6 changes: 6 additions & 0 deletions src/ApiMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <summary>
/// Used for test purposes only.
/// </summary>
internal static class ApiMarker
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public AzureDigitalTwinHealthCheck(TokenCredential tokenCredential)
TokenCredential = tokenCredential ?? throw new ArgumentNullException(nameof(tokenCredential));
}


protected AzureDigitalTwinsManagementClient CreateManagementClient()
{
var credential = ServiceClientCredentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke
SaveGeneralizedReport(report, client);
}


return Task.CompletedTask;
}

Expand Down
1 change: 0 additions & 1 deletion src/HealthChecks.UI/Core/UIResourceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void Map(IApplicationBuilder app, Options options)
});
});


foreach (var item in styleSheets)
{
app.Map(item.ResourcePath, appBuilder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static IEndpointConventionBuilder MapHealthChecksUI(this IEndpointRouteBu
.UseMiddleware<UIWebHooksApiMiddleware>()
.Build();


var embeddedResourcesAssembly = typeof(UIResource).Assembly;

var resourcesEndpoints =
Expand Down
1 change: 0 additions & 1 deletion src/HealthChecks.UI/assets/healthchecksui.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ h4 {
min-width: 3.5rem;
}


.hc-button:hover {
background-image: var(--bgImageDarken);
}
Expand Down
3 changes: 1 addition & 2 deletions src/HealthChecks.UI/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import fetchers from './api/fetchers';
import { AlertPanel } from './components/AlertPanel';
import { useQuery } from 'react-query';


interface AppProps {
uiSettings: UISettings;
}
Expand Down Expand Up @@ -58,4 +57,4 @@ const App: FunctionComponent<AppProps> = ({ uiSettings }) => {
);
}

export { App };
export { App };
3 changes: 1 addition & 2 deletions src/HealthChecks.UI/client/components/AlertPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ const AlertPanel: FunctionComponent<AlertPanelProps> = ({ message }) =>
</div>
);


export { AlertPanel };
export { AlertPanel };
5 changes: 2 additions & 3 deletions src/HealthChecks.UI/client/components/LivenessMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ interface LivenessMenuProps {

const LivenessMenu: FunctionComponent<LivenessMenuProps> = ({ running, onRunningClick, pollingInterval }) => {


return (
<div className="hc-refesh-group">
<div className="hc-refesh-group">
<span>Polling interval: <b>{pollingInterval}</b> secs</span>
<button
onClick={onRunningClick}
Expand All @@ -21,4 +20,4 @@ const LivenessMenu: FunctionComponent<LivenessMenuProps> = ({ running, onRunning
</div>)
};

export { LivenessMenu };
export { LivenessMenu };
7 changes: 2 additions & 5 deletions src/HealthChecks.UI/client/components/LivenessTable.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent } from 'react';
import { Liveness } from '../typings/models';
import { discoveryServices, getStatusConfig } from '../healthChecksResources';
import { CheckTable } from './CheckTable';


interface LivenessTableProps {
livenessData: Array<Liveness>;
collapseAll: (event: any) => void;
Expand All @@ -28,7 +27,6 @@ const LivenessTable: FunctionComponent<LivenessTableProps> = ({ livenessData, ex
});
};


const toggleAll = (event: any) => {
let { currentTarget } = event;
let iconToggle = currentTarget.getElementsByClassName('js-toggle-all')[0];
Expand Down Expand Up @@ -109,7 +107,6 @@ const LivenessTable: FunctionComponent<LivenessTableProps> = ({ livenessData, ex
);
};


const getDiscoveryServiceImage = (discoveryService: string) => {
if (discoveryService != null) {
let discoveryServiceImage = discoveryServices.find(
Expand Down Expand Up @@ -140,4 +137,4 @@ const toggleVisibility = (event: any) => {
iconImage.setAttribute('title', isHidden ? 'hide info' : 'expand info');
};

export { LivenessTable };
export { LivenessTable };
3 changes: 1 addition & 2 deletions src/HealthChecks.UI/client/pages/LivenessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getHealthChecks } from '../api/fetchers';
import { LivenessMenu } from '../components/LivenessMenu';
import { AlertPanel } from '../components/AlertPanel';


interface LivenessState {
error: Nullable<string>;
pollingIntervalSetting: string | number;
Expand Down Expand Up @@ -95,4 +94,4 @@ const LivenessPage: React.FunctionComponent<LivenessProps> = ({ apiSettings }) =

};

export { LivenessPage };
export { LivenessPage };
5 changes: 2 additions & 3 deletions src/HealthChecks.UI/client/pages/WebhooksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { useQuery } from 'react-query';
import fetchers from '../api/fetchers';
import { AlertPanel } from '../components/AlertPanel';


interface WebHooksPageState {
webhooks: Array<WebHook>;
}

const WebhooksPage = () => {

const { data: webhooks, isError } = useQuery("webhooks", fetchers.getWebhooks, {retry: 1});
const { data: webhooks, isError } = useQuery("webhooks", fetchers.getWebhooks, {retry: 1});

const renderWebhooks = (webhooks: Array<WebHook>) => {
let webHooksChunk = chunkArray(webhooks, 2);
Expand Down Expand Up @@ -64,4 +63,4 @@ const WebhooksPage = () => {

};

export { WebhooksPage };
export { WebhooksPage };
Loading