Skip to content

Commit

Permalink
Refactor Keycloak resource constants and tests
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
paulomorgado committed Jan 17, 2025
1 parent c219e7d commit c874176
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static class KeycloakResourceBuilderExtensions
{
private const string AdminEnvVarName = "KEYCLOAK_ADMIN";
private const string AdminPasswordEnvVarName = "KEYCLOAK_ADMIN_PASSWORD";
private const string HealthCheckEnvVarName = "KC_HEALTH_ENABLED";
private const string HealthCheckEnvVarName = "KC_HEALTH_ENABLED"; // As per https://www.keycloak.org/observability/health
private const int DefaultContainerPort = 8080;
private const string ManagementInterfaceContainerPort = 9000;
private const int ManagementInterfaceContainerPort = 9000; // As per https://www.keycloak.org/server/management-interface
private const string ManagementEndpointName = "management";
private const string RealmImportDirectory = "/opt/keycloak/data/import";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ public void AddKeycloakWithDefaultsAddsAnnotationMetadata()
var containerResource = Assert.Single(appModel.Resources.OfType<KeycloakResource>());
Assert.Equal(resourceName, containerResource.Name);

var endpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == "http"));
const string defaultEndpointName = "http";

var endpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == defaultEndpointName));
Assert.Equal(8080, endpoint.TargetPort);
Assert.False(endpoint.IsExternal);
Assert.Equal("http", endpoint.Name);
Assert.Equal(defaultEndpointName, endpoint.Name);
Assert.Null(endpoint.Port);
Assert.Equal(ProtocolType.Tcp, endpoint.Protocol);
Assert.Equal("http", endpoint.Transport);
Assert.Equal("http", endpoint.UriScheme);

var healthEndpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == "health"));
const string managementEndpointName = "management";

var healthEndpoint = Assert.Single(containerResource.Annotations.OfType<EndpointAnnotation>().Where(e => e.Name == managementEndpointName));
Assert.Equal(9000, healthEndpoint.TargetPort);
Assert.False(healthEndpoint.IsExternal);
Assert.Equal("health", healthEndpoint.Name);
Assert.Equal(managementEndpointName, healthEndpoint.Name);
Assert.Null(healthEndpoint.Port);
Assert.Equal(ProtocolType.Tcp, healthEndpoint.Protocol);
Assert.Equal("http", healthEndpoint.Transport);
Expand Down Expand Up @@ -161,7 +165,7 @@ public async Task VerifyManifest()
"transport": "http",
"targetPort": 8080
},
"health": {
"management": {
"scheme": "http",
"protocol": "tcp",
"transport": "http",
Expand Down

0 comments on commit c874176

Please sign in to comment.