Skip to content

Commit 2cd0254

Browse files
CopilotJerryNixon
andcommitted
Improve test to use RuntimeConfig with mixed entity types
Co-authored-by: JerryNixon <[email protected]>
1 parent b7d59f6 commit 2cd0254

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

src/Service.Tests/Configuration/HealthEndpointTests.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,24 +565,54 @@ private static RuntimeConfig CreateRuntimeConfig(Dictionary<string, Entity> enti
565565
}
566566

567567
/// <summary>
568-
/// Verifies stored procedures are excluded from health checks.
568+
/// Verifies that when filtering entities for health checks,
569+
/// stored procedures are excluded while tables and views are included.
570+
/// This matches the filter logic in HealthCheckHelper.UpdateEntityHealthCheckResultsAsync.
569571
/// </summary>
570572
[TestMethod]
571573
public void HealthChecks_ExcludeStoredProcedures()
572574
{
573-
Entity storedProcedure = new(
574-
Source: new("test", EntitySourceType.StoredProcedure, null, null),
575-
GraphQL: new("test", "tests"),
575+
// Create a config with table, view, and stored procedure entities
576+
RuntimeConfig runtimeConfig = SetupCustomConfigFile(
577+
enableGlobalHealth: true,
578+
enableGlobalRest: true,
579+
enableGlobalGraphql: true,
580+
enabledGlobalMcp: true,
581+
enableDatasourceHealth: true,
582+
enableEntityHealth: true,
583+
enableEntityRest: true,
584+
enableEntityGraphQL: true);
585+
586+
// Add a stored procedure entity to the existing config
587+
Entity storedProcEntity = new(
588+
Source: new("GetData", EntitySourceType.StoredProcedure, null, null),
589+
GraphQL: new("getData", "getDataList"),
576590
Rest: new(Enabled: true),
577591
Permissions: new[] { ConfigurationTests.GetMinimalPermissionConfig(AuthorizationResolver.ROLE_ANONYMOUS) },
578592
Mappings: null,
579593
Relationships: null,
580594
Fields: null);
581595

582-
// Apply the filter logic used in HealthCheckHelper - stored procedures should be excluded
583-
bool isIncludedInHealthCheck = storedProcedure.IsEntityHealthEnabled && storedProcedure.Source.Type != EntitySourceType.StoredProcedure;
584-
585-
Assert.IsFalse(isIncludedInHealthCheck);
596+
Dictionary<string, Entity> entitiesWithStoredProc = new(runtimeConfig.Entities.Entities)
597+
{
598+
{ "GetData", storedProcEntity }
599+
};
600+
601+
RuntimeConfig configWithStoredProc = runtimeConfig with
602+
{
603+
Entities = new RuntimeEntities(entitiesWithStoredProc)
604+
};
605+
606+
// Apply the same filter used in HealthCheckHelper.UpdateEntityHealthCheckResultsAsync
607+
List<KeyValuePair<string, Entity>> healthCheckEntities = configWithStoredProc.Entities.Entities
608+
.Where(e => e.Value.IsEntityHealthEnabled && e.Value.Source.Type != EntitySourceType.StoredProcedure)
609+
.ToList();
610+
611+
// Verify stored procedure is excluded and table is included
612+
Assert.IsFalse(healthCheckEntities.Any(e => e.Value.Source.Type == EntitySourceType.StoredProcedure),
613+
"Stored procedures should be excluded from health checks");
614+
Assert.IsTrue(healthCheckEntities.Any(e => e.Value.Source.Type == EntitySourceType.Table),
615+
"Tables should be included in health checks");
586616
}
587617

588618
private static void WriteToCustomConfigFile(RuntimeConfig runtimeConfig)

0 commit comments

Comments
 (0)