Skip to content

Commit 84907bd

Browse files
committed
Update KubeServiceDiscoveryProviderTests
1 parent ae9f05e commit 84907bd

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

test/Ocelot.UnitTests/Kubernetes/KubeServiceDiscoveryProviderTests.cs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Ocelot.UnitTests.Kubernetes
2121
public class KubeServiceDiscoveryProviderTests : IDisposable
2222
{
2323
private IWebHost _fakeKubeBuilder;
24-
private ServiceV1 _serviceEntries;
24+
private EndpointsV1 _endpointEntries;
2525
private Kube _provider;
2626
private readonly string _serviceName;
2727
private readonly string _namespaces;
@@ -41,15 +41,15 @@ public KubeServiceDiscoveryProviderTests()
4141
_port = 8001;
4242
_kubeHost = "localhost";
4343
_fakekubeServiceDiscoveryUrl = $"http://{_kubeHost}:{_port}";
44-
_serviceEntries = new ServiceV1();
44+
_endpointEntries = new EndpointsV1();
4545
_factory = new Mock<IOcelotLoggerFactory>();
4646

4747
var option = new KubeClientOptions
4848
{
4949
ApiEndPoint = new Uri(_fakekubeServiceDiscoveryUrl),
5050
AccessToken = "txpc696iUhbVoudg164r93CxDTrKRVWG",
5151
AuthStrategy = KubeClient.KubeAuthStrategy.BearerToken,
52-
AllowInsecure = true
52+
AllowInsecure = true,
5353
};
5454

5555
_clientFactory = KubeApiClient.Create(option);
@@ -58,7 +58,7 @@ public KubeServiceDiscoveryProviderTests()
5858
var config = new KubeRegistryConfiguration()
5959
{
6060
KeyOfServiceInK8s = _serviceName,
61-
KubeNamespace = _namespaces
61+
KubeNamespace = _namespaces,
6262
};
6363
_provider = new Kube(config, _factory.Object, _clientFactory);
6464
}
@@ -67,33 +67,29 @@ public KubeServiceDiscoveryProviderTests()
6767
public void should_return_service_from_k8s()
6868
{
6969
var token = "Bearer txpc696iUhbVoudg164r93CxDTrKRVWG";
70-
var serviceEntryOne = new ServiceV1()
70+
var endPointEntryOne = new EndpointsV1
7171
{
72-
Kind = "service",
72+
Kind = "endpoint",
7373
ApiVersion = "1.0",
7474
Metadata = new ObjectMetaV1()
7575
{
76-
Namespace = "dev"
76+
Namespace = "dev",
7777
},
78-
Spec = new ServiceSpecV1()
79-
{
80-
ClusterIP = "localhost"
81-
},
82-
Status = new ServiceStatusV1()
83-
{
84-
LoadBalancer = new LoadBalancerStatusV1()
85-
}
8678
};
87-
88-
serviceEntryOne.Spec.Ports.Add(
89-
new ServicePortV1()
90-
{
91-
Port = 80
92-
}
93-
);
79+
var endpointSubsetV1 = new EndpointSubsetV1();
80+
endpointSubsetV1.Addresses.Add(new EndpointAddressV1()
81+
{
82+
Ip = "127.0.0.1",
83+
Hostname = "localhost",
84+
});
85+
endpointSubsetV1.Ports.Add(new EndpointPortV1()
86+
{
87+
Port = 80,
88+
});
89+
endPointEntryOne.Subsets.Add(endpointSubsetV1);
9490

9591
this.Given(x => GivenThereIsAFakeKubeServiceDiscoveryProvider(_fakekubeServiceDiscoveryUrl, _serviceName, _namespaces))
96-
.And(x => GivenTheServicesAreRegisteredWithKube(serviceEntryOne))
92+
.And(x => GivenTheServicesAreRegisteredWithKube(endPointEntryOne))
9793
.When(x => WhenIGetTheServices())
9894
.Then(x => ThenTheCountIs(1))
9995
.And(_ => _receivedToken.ShouldBe(token))
@@ -110,9 +106,9 @@ private void WhenIGetTheServices()
110106
_services = _provider.Get().GetAwaiter().GetResult();
111107
}
112108

113-
private void GivenTheServicesAreRegisteredWithKube(ServiceV1 serviceEntries)
109+
private void GivenTheServicesAreRegisteredWithKube(EndpointsV1 endpointEntries)
114110
{
115-
_serviceEntries = serviceEntries;
111+
_endpointEntries = endpointEntries;
116112
}
117113

118114
private void GivenThereIsAFakeKubeServiceDiscoveryProvider(string url, string serviceName, string namespaces)
@@ -127,14 +123,14 @@ private void GivenThereIsAFakeKubeServiceDiscoveryProvider(string url, string se
127123
{
128124
app.Run(async context =>
129125
{
130-
if (context.Request.Path.Value == $"/api/v1/namespaces/{namespaces}/services/{serviceName}")
126+
if (context.Request.Path.Value == $"/api/v1/namespaces/{namespaces}/endpoints/{serviceName}")
131127
{
132128
if (context.Request.Headers.TryGetValue("Authorization", out var values))
133129
{
134130
_receivedToken = values.First();
135131
}
136132

137-
var json = JsonConvert.SerializeObject(_serviceEntries);
133+
var json = JsonConvert.SerializeObject(_endpointEntries);
138134
context.Response.Headers.Add("Content-Type", "application/json");
139135
await context.Response.WriteAsync(json);
140136
}

0 commit comments

Comments
 (0)