Skip to content

Commit ae5859a

Browse files
committed
Add more unit tests
1 parent 22668e7 commit ae5859a

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

operator/src/test/java/oracle/kubernetes/operator/helpers/ServicePresenceTest.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7+
import static oracle.kubernetes.operator.LabelConstants.CLUSTERNAME_LABEL;
78
import static oracle.kubernetes.operator.LabelConstants.DOMAINUID_LABEL;
89
import static oracle.kubernetes.operator.LabelConstants.SERVERNAME_LABEL;
910
import static oracle.kubernetes.operator.ProcessingConstants.CLUSTER_NAME;
@@ -237,6 +238,17 @@ public void onDeleteEventWithNewerClusterService_removeIt() {
237238
assertThat(info.getClusterService(CLUSTER), nullValue());
238239
}
239240

241+
@Test
242+
public void whenEventContainsServiceWithClusterNameAndNoTypeLabel_addAsClusterService() {
243+
V1Service service =
244+
new V1Service().metadata(createMetadata().putLabelsItem(CLUSTERNAME_LABEL, CLUSTER));
245+
Watch.Response<V1Service> event = WatchEvent.createAddedEvent(service).toWatchResponse();
246+
247+
processor.dispatchServiceWatch(event);
248+
249+
assertThat(info.getClusterService(CLUSTER), sameInstance(service));
250+
}
251+
240252
@Test
241253
public void onAddEventWithNoRecordedServerService_addIt() {
242254
V1Service newService = createServerService();
@@ -351,6 +363,21 @@ public void onDeleteEventWithNewerServerService_removeIt() {
351363
assertThat(info.getServerService(SERVER), nullValue());
352364
}
353365

366+
@Test
367+
public void whenEventContainsServiceWithServerNameAndNoTypeLabel_addAsServerService() {
368+
V1Service service =
369+
new V1Service()
370+
.metadata(
371+
createMetadata()
372+
.putLabelsItem(CLUSTERNAME_LABEL, CLUSTER)
373+
.putLabelsItem(SERVERNAME_LABEL, SERVER));
374+
Watch.Response<V1Service> event = WatchEvent.createAddedEvent(service).toWatchResponse();
375+
376+
processor.dispatchServiceWatch(event);
377+
378+
assertThat(info.getServerService(SERVER), sameInstance(service));
379+
}
380+
354381
@Test
355382
public void onAddEventWithNoRecordedExternalService_addIt() {
356383
V1Service newService = createExternalService();
@@ -482,6 +509,10 @@ private V1Service withTimeAndVersion(V1Service service) {
482509
return service;
483510
}
484511

512+
private DateTime getDateTime() {
513+
return new DateTime(++clock);
514+
}
515+
485516
private V1ObjectMeta createMetadata() {
486517
return new V1ObjectMeta()
487518
.namespace(NS)
@@ -490,7 +521,30 @@ private V1ObjectMeta createMetadata() {
490521
.resourceVersion(RESOURCE_VERSION);
491522
}
492523

493-
private DateTime getDateTime() {
494-
return new DateTime(++clock);
524+
@Test
525+
public void whenClusterServiceAdded_recordforCluster() {
526+
V1Service clusterService = createClusterService();
527+
528+
ServiceHelper.addToPresence(info, clusterService);
529+
530+
assertThat(info.getClusterService(CLUSTER), sameInstance(clusterService));
531+
}
532+
533+
@Test
534+
public void whenServerServiceAdded_recordforServer() {
535+
V1Service serverService = createServerService();
536+
537+
ServiceHelper.addToPresence(info, serverService);
538+
539+
assertThat(info.getServerService(SERVER), sameInstance(serverService));
540+
}
541+
542+
@Test
543+
public void whenExternalServiceAdded_recordforServer() {
544+
V1Service externalService = createExternalService();
545+
546+
ServiceHelper.addToPresence(info, externalService);
547+
548+
assertThat(info.getExternalService(SERVER), sameInstance(externalService));
495549
}
496550
}

0 commit comments

Comments
 (0)