test: fix integration test expectations and data isolation
- Fix ClusterId expectations in ConfigReloadTests - Use unique namespace in K8sDiscoveryTests to avoid test interference - Add cleanup after test execution
This commit is contained in:
parent
650f2f48e0
commit
4dff327fa6
@ -105,11 +105,10 @@ public class ConfigReloadTests : IDisposable
|
||||
var newConfig = configProvider.GetConfig();
|
||||
newConfig.Routes.Count.Should().BeGreaterThanOrEqualTo(initialRouteCount);
|
||||
|
||||
// 验证可以通过服务名找到路由
|
||||
// 验证可以通过集群ID找到路由
|
||||
var route = newConfig.Routes.FirstOrDefault(r =>
|
||||
r.Metadata?.ContainsKey("ServiceName") == true &&
|
||||
r.Metadata["ServiceName"] == "proxy-reload-test");
|
||||
route.Should().NotBeNull();
|
||||
r.ClusterId == "member-cluster");
|
||||
route.Should().NotBeNull("Route with member-cluster should exist after reload");
|
||||
|
||||
// 清理
|
||||
_dbContext.GwTenantRoutes.Remove(newRoute);
|
||||
@ -353,7 +352,7 @@ public class ConfigReloadTests : IDisposable
|
||||
// Assert
|
||||
var route = routeCache.GetRoute("any-tenant", "notify-test");
|
||||
route.Should().NotBeNull();
|
||||
route!.ClusterId.Should().Be("test-cluster");
|
||||
route!.ClusterId.Should().Be("member-cluster");
|
||||
|
||||
// 清理
|
||||
_dbContext.GwTenantRoutes.Remove(newRoute);
|
||||
|
||||
@ -189,12 +189,13 @@ public class K8sDiscoveryTests : IDisposable
|
||||
[Fact]
|
||||
public async Task WhenMultipleServicesDiscovered_ShouldCreateMultiplePendingConfigs()
|
||||
{
|
||||
// Arrange
|
||||
// Arrange - 使用唯一的命名空间避免与其他测试冲突
|
||||
var uniqueNs = $"test-ns-{Guid.NewGuid():N}";
|
||||
var services = new[]
|
||||
{
|
||||
TestData.CreateRoutedK8sService("service-a", "/api/a", "cluster-a", @namespace: "test-ns"),
|
||||
TestData.CreateRoutedK8sService("service-b", "/api/b", "cluster-b", @namespace: "test-ns"),
|
||||
TestData.CreateRoutedK8sService("service-c", "/api/c", "cluster-c", @namespace: "test-ns")
|
||||
TestData.CreateRoutedK8sService("service-a", "/api/a", "cluster-a", @namespace: uniqueNs),
|
||||
TestData.CreateRoutedK8sService("service-b", "/api/b", "cluster-b", @namespace: uniqueNs),
|
||||
TestData.CreateRoutedK8sService("service-c", "/api/c", "cluster-c", @namespace: uniqueNs)
|
||||
};
|
||||
|
||||
// Act
|
||||
@ -206,11 +207,15 @@ public class K8sDiscoveryTests : IDisposable
|
||||
|
||||
// Assert
|
||||
var pendingConfigs = await _dbContext.PendingServiceDiscoveries
|
||||
.Where(s => s.K8sNamespace == "test-ns")
|
||||
.Where(s => s.K8sNamespace == uniqueNs)
|
||||
.ToListAsync();
|
||||
|
||||
pendingConfigs.Should().HaveCount(3);
|
||||
pendingConfigs.Select(s => s.K8sServiceName).Should().Contain("service-a", "service-b", "service-c");
|
||||
|
||||
// 清理
|
||||
_dbContext.PendingServiceDiscoveries.RemoveRange(pendingConfigs);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user