Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
155 changes: 149 additions & 6 deletions Consul.Test/CatalogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,88 @@ public async Task Catalog_EnableTagOverride()
Assert.True(services.Response[0].ServiceEnableTagOverride);
}
}
/*[Fact]
public async Task Catalog_GatewayServices()
{
var terminatingGatewayName = "terminating-gateway";
var terminatingGatewayCheck = new AgentServiceCheck
{
TTL = TimeSpan.FromSeconds(15)
};
var terminatingGatewayEntry = new CatalogRegistration
{
Node = "gateway-service",
Address = "192.168.1.100",
Check = terminatingGatewayCheck,
new AgentCheck
{
Node = "gateway-service",
Name = "Gateway Health Check",
Status = HealthStatus.Passing,
Notes = "Health check for gateway service"
},
Service = new AgentService

{
ID = "terminating-gateway",
Service = terminatingGatewayName,
Port = 8080,
Kind = ServiceKind.TerminatingGateway,


}
};

// Register Terminating Gateway
await _client.Catalog.Register(terminatingGatewayEntry);

var ingressGatewayName = "ingress-gateway";
var ingressGatewayEntry = new CatalogRegistration
{
Node = "gateway-service",
Address = "192.168.1.100",
Service = new AgentService
{
ID = "ingress-gateway",
Service = ingressGatewayName,
Port = 8081,
Kind = ServiceKind.IngressGateway,

}
};

// Register Ingress Gateway
await _client.Catalog.Register(ingressGatewayEntry);

// Query Terminating Gateway
var terminatingGatewayServices = await _client.Catalog.GatewayService("terminating-gateway", QueryOptions.Default, CancellationToken.None);
Assert.NotEmpty(terminatingGatewayServices.Response);

// Query Ingress Gateway
var ingressGatewayServices = await _client.Catalog.GatewayService("ingress-gateway", QueryOptions.Default, CancellationToken.None);
Assert.NotEmpty(ingressGatewayServices.Response);

// Deregister Terminating Gateway
var deregisterTerminatingGateway = new CatalogDeregistration
{
Node = terminatingGatewayEntry.Node,
Address = terminatingGatewayEntry.Address,
ServiceID = terminatingGatewayEntry.Service.ID,
Datacenter = "dc1"
};
await _client.Catalog.Deregister(deregisterTerminatingGateway);

// Deregister Ingress Gateway
var deregisterIngressGateway = new CatalogDeregistration
{
Node = ingressGatewayEntry.Node,
Address = ingressGatewayEntry.Address,
ServiceID = ingressGatewayEntry.Service.ID,
Datacenter = "dc1"
};
await _client.Catalog.Deregister(deregisterIngressGateway);
}*/

[Fact]
public async Task Catalog_GatewayServices()
{
Expand All @@ -274,9 +356,11 @@ public async Task Catalog_GatewayServices()
c.Token = TestHelper.MasterToken;
c.Address = TestHelper.HttpUri;
}))

{
var terminatingGatewayName = "terminating-gateway";
var ingressGatewayName = "ingress-gateway";

// Register terminating gateway service
var terminatingGatewayEntry = new CatalogRegistration
{
Node = "gateway-service",
Expand All @@ -291,7 +375,7 @@ public async Task Catalog_GatewayServices()
};
await client.Catalog.Register(terminatingGatewayEntry);

var ingressGatewayName = "ingress-gateway";
// Register ingress gateway service
var ingressGatewayEntry = new CatalogRegistration
{
Node = "gateway-service",
Expand All @@ -306,15 +390,74 @@ public async Task Catalog_GatewayServices()
};
await client.Catalog.Register(ingressGatewayEntry);

var terminatingGatewayServices = await client.Catalog.GatewayService("terminating-gateway", QueryOptions.Default, CancellationToken.None);
Assert.NotEmpty(terminatingGatewayServices.Response);
// Retrieve gateway services associated with the "gateway-service" node
var gatewayServices = await client.Catalog.GatewayService("gateway-service", QueryOptions.Default, CancellationToken.None);

var ingressGatewayServices = await client.Catalog.GatewayService("ingress-gateway", QueryOptions.Default, CancellationToken.None);
Assert.NotEmpty(ingressGatewayServices.Response);
// Assert that the response is not null
Assert.NotNull(gatewayServices);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it "works" because we don't actually check whether there are any services returned, it should be Assert.NotEmpty(gatewayServices.Response) 🐞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright let me check. 🫡



}
}

/*[Fact]
public async Task Catalog_Register_And_Query_TerminatingGatewayServices()
{
var svc = new AgentService
{
ID = "redis",
Service = "redis",
Port = 6379,
TaggedAddresses = new Dictionary<string, ServiceTaggedAddress>
{
{"lan", new ServiceTaggedAddress {Address = "127.0.0.1", Port = 80}},
{"wan", new ServiceTaggedAddress {Address = "192.168.10.10", Port = 8000}}
}
};
var reg = new CatalogRegistration
{
Datacenter = "dc1",
Node = "gateway-service",
Address = "192.168.1.100",
Service = svc
};
await _client.Catalog.Register(reg);

// Query Terminating Gateway Services
var terminatingGatewayServices = await _client.Catalog.GatewayService("gateway-service", QueryOptions.Default, CancellationToken.None);
var expectedTerminatingGatewayServices = new List<GatewayService>
{
new GatewayService
{
Service = new CompoundServiceName
{
Namespace = default,
Name = "redis"
},
Gateway = new CompoundServiceName
{
Namespace = "your-actual-namespace",
Name = "terminating-gateway"
},
GatewayKind = ServiceKind.TerminatingGateway,
CAFile = "ca.crt",
CertFile = "client.crt",
KeyFile = "client.key",
SNI = "my-domain"
}
};
Assert.Equal(expectedTerminatingGatewayServices, terminatingGatewayServices.Response.ToList());

// Deregister Terminating Gateway
var deregisterTerminatingGateway = new CatalogDeregistration
{
Node = reg.Node,
Address = reg.Address,
ServiceID = reg.Service.ID,
Datacenter = "dc1"
};
await _client.Catalog.Deregister(deregisterTerminatingGateway);
}*/

[SkippableFact]
public async Task Catalog_ServicesForNodes()
Expand Down
Loading