Skip to content

Commit c874176

Browse files
committed
Refactor Keycloak resource constants and tests
- Retained `HealthCheckEnvVarName` constant; changed type of `ManagementInterfaceContainerPort` to `int` for clarity. - Introduced `defaultEndpointName` and `managementEndpointName` variables in tests to replace hardcoded strings for improved readability. - Updated JSON structure in `VerifyManifest` to change key from "health" to "management" to align with new naming conventions.
1 parent c219e7d commit c874176

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Aspire.Hosting.Keycloak/KeycloakResourceBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static class KeycloakResourceBuilderExtensions
1414
{
1515
private const string AdminEnvVarName = "KEYCLOAK_ADMIN";
1616
private const string AdminPasswordEnvVarName = "KEYCLOAK_ADMIN_PASSWORD";
17-
private const string HealthCheckEnvVarName = "KC_HEALTH_ENABLED";
17+
private const string HealthCheckEnvVarName = "KC_HEALTH_ENABLED"; // As per https://www.keycloak.org/observability/health
1818
private const int DefaultContainerPort = 8080;
19-
private const string ManagementInterfaceContainerPort = 9000;
19+
private const int ManagementInterfaceContainerPort = 9000; // As per https://www.keycloak.org/server/management-interface
2020
private const string ManagementEndpointName = "management";
2121
private const string RealmImportDirectory = "/opt/keycloak/data/import";
2222

tests/Aspire.Hosting.Keycloak.Tests/KeycloakResourceBuilderTests.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ public void AddKeycloakWithDefaultsAddsAnnotationMetadata()
2626
var containerResource = Assert.Single(appModel.Resources.OfType<KeycloakResource>());
2727
Assert.Equal(resourceName, containerResource.Name);
2828

29-
var endpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == "http"));
29+
const string defaultEndpointName = "http";
30+
31+
var endpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == defaultEndpointName));
3032
Assert.Equal(8080, endpoint.TargetPort);
3133
Assert.False(endpoint.IsExternal);
32-
Assert.Equal("http", endpoint.Name);
34+
Assert.Equal(defaultEndpointName, endpoint.Name);
3335
Assert.Null(endpoint.Port);
3436
Assert.Equal(ProtocolType.Tcp, endpoint.Protocol);
3537
Assert.Equal("http", endpoint.Transport);
3638
Assert.Equal("http", endpoint.UriScheme);
3739

38-
var healthEndpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == "health"));
40+
const string managementEndpointName = "management";
41+
42+
var healthEndpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == managementEndpointName));
3943
Assert.Equal(9000, healthEndpoint.TargetPort);
4044
Assert.False(healthEndpoint.IsExternal);
41-
Assert.Equal("health", healthEndpoint.Name);
45+
Assert.Equal(managementEndpointName, healthEndpoint.Name);
4246
Assert.Null(healthEndpoint.Port);
4347
Assert.Equal(ProtocolType.Tcp, healthEndpoint.Protocol);
4448
Assert.Equal("http", healthEndpoint.Transport);
@@ -161,7 +165,7 @@ public async Task VerifyManifest()
161165
"transport": "http",
162166
"targetPort": 8080
163167
},
164-
"health": {
168+
"management": {
165169
"scheme": "http",
166170
"protocol": "tcp",
167171
"transport": "http",

0 commit comments

Comments
 (0)