-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KOGITO-9605 Created abstract test class that implementations of Kuber…
…netesServiceCatalog must cover
- Loading branch information
Showing
10 changed files
with
326 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...rc/test/java/org/kie/kogito/addons/k8s/resource/catalog/KubernetesServiceCatalogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.addons.k8s.resource.catalog; | ||
|
||
import java.net.URI; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KNATIVE; | ||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KUBERNETES; | ||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.OPENSHIFT; | ||
|
||
/** | ||
* Test classes for implementations of {@link KubernetesServiceCatalog} must extend this class. | ||
* It tests all use cases an implementation of {@link KubernetesServiceCatalog} must cover. | ||
*/ | ||
public abstract class KubernetesServiceCatalogTest { | ||
|
||
private static final String EXPECTED_KNATIVE_URI = "http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io"; | ||
|
||
private static final String EXPECTED_KUBERNETES_URI = "http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io"; | ||
|
||
private static final String EXPECTED_OPENSHIFT_URI = "http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io"; | ||
|
||
private static final String NAMESPACE = "test"; | ||
|
||
private static final String KNATIVE_SERVICENAME = "serverless-workflow-greeting-quarkus"; | ||
|
||
private static final String KUBERNETES_SERVICENAME = "serverless-workflow-greeting-quarkus-kubernetes"; | ||
|
||
private static final String OPENSHIFT_SERVICENAME = "serverless-workflow-greeting-quarkus-openshift"; | ||
|
||
private static final String NAMESPACE_KNATIVE_SERVICENAME = NAMESPACE + '/' + KNATIVE_SERVICENAME; | ||
|
||
private static final String NAMESPACE_KUBERNETES_SERVICENAME = NAMESPACE + '/' + KUBERNETES_SERVICENAME; | ||
|
||
private static final String NAMESPACE_OPENSHIFT_SERVICENAME = NAMESPACE + '/' + OPENSHIFT_SERVICENAME; | ||
|
||
private static final String GVK = "services.v1.serving.knative.dev"; | ||
|
||
private static final String GVK_KNATIVE_SERVICENAME = GVK + '/' + KNATIVE_SERVICENAME; | ||
|
||
private static final String GVK_NAMESPACE_SERVICENAME = GVK + '/' + NAMESPACE_KNATIVE_SERVICENAME; | ||
|
||
private static final String GVK_KUBERNETES_SERVICENAME = GVK + '/' + KUBERNETES_SERVICENAME; | ||
|
||
private static final String GVK_NAMESPACE_KUBERNETES_SERVICENAME = GVK + '/' + NAMESPACE_KUBERNETES_SERVICENAME; | ||
|
||
private static final String GVK_OPENSHIFT_SERVICENAME = GVK + '/' + OPENSHIFT_SERVICENAME; | ||
|
||
private static final String GVK_NAMESPACE_OPENSHIFT_SERVICENAME = GVK + '/' + NAMESPACE_OPENSHIFT_SERVICENAME; | ||
|
||
private final KubernetesServiceCatalog kubernetesServiceCatalog; | ||
|
||
protected KubernetesServiceCatalogTest(KubernetesServiceCatalog kubernetesServiceCatalog) { | ||
this.kubernetesServiceCatalog = kubernetesServiceCatalog; | ||
} | ||
|
||
protected final String getNamespace() { | ||
return NAMESPACE; | ||
} | ||
|
||
protected final String getKnativeServiceName() { | ||
return KNATIVE_SERVICENAME; | ||
} | ||
|
||
protected final String getKubernetesServiceName() { | ||
return KUBERNETES_SERVICENAME; | ||
} | ||
|
||
protected final String getOpenshiftServicename() { | ||
return OPENSHIFT_SERVICENAME; | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("possibleUriFormats") | ||
void getServiceAddress(KubernetesProtocol kubernetesProtocol, String coordinates, String expectedUri) { | ||
KubernetesServiceCatalogKey key = new KubernetesServiceCatalogKey(kubernetesProtocol, coordinates); | ||
assertThat(kubernetesServiceCatalog.getServiceAddress(key)) | ||
.map(URI::toString) | ||
.hasValue(expectedUri); | ||
} | ||
|
||
protected static Stream<Arguments> possibleUriFormats() { | ||
return Stream.of( | ||
Arguments.of(KNATIVE, KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), | ||
Arguments.of(KNATIVE, NAMESPACE_KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), | ||
Arguments.of(KNATIVE, GVK_KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), | ||
Arguments.of(KNATIVE, GVK_NAMESPACE_SERVICENAME, EXPECTED_KNATIVE_URI), | ||
|
||
Arguments.of(KUBERNETES, GVK_KUBERNETES_SERVICENAME, EXPECTED_KUBERNETES_URI), | ||
Arguments.of(KUBERNETES, GVK_NAMESPACE_KUBERNETES_SERVICENAME, EXPECTED_KUBERNETES_URI), | ||
|
||
Arguments.of(OPENSHIFT, GVK_OPENSHIFT_SERVICENAME, EXPECTED_OPENSHIFT_URI), | ||
Arguments.of(OPENSHIFT, GVK_NAMESPACE_OPENSHIFT_SERVICENAME, EXPECTED_OPENSHIFT_URI)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ogito/addons/quarkus/fabric8/k8s/service/catalog/Fabric8KubernetesServiceCatalogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.kie.kogito.addons.quarkus.fabric8.k8s.service.catalog; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogTest; | ||
|
||
import io.fabric8.kubernetes.client.server.mock.KubernetesServer; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.kubernetes.client.KubernetesTestServer; | ||
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; | ||
|
||
import static org.kie.kogito.addons.quarkus.k8s.test.utils.KnativeResourceDiscoveryTestUtil.createServiceIfNotExists; | ||
|
||
@QuarkusTest | ||
@WithKubernetesTestServer | ||
class Fabric8KubernetesServiceCatalogTest extends KubernetesServiceCatalogTest { | ||
|
||
@KubernetesTestServer | ||
KubernetesServer mockServer; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", getNamespace(), getKnativeServiceName()); | ||
createServiceIfNotExists(mockServer, "knative/quarkus-greeting-kubernetes.yaml", getNamespace(), getKubernetesServiceName()); | ||
createServiceIfNotExists(mockServer, "knative/quarkus-greeting-openshift.yaml", getNamespace(), getOpenshiftServicename()); | ||
} | ||
|
||
@Inject | ||
Fabric8KubernetesServiceCatalogTest(Fabric8KubernetesServiceCatalog fabric8KubernetesServiceCatalog) { | ||
super(fabric8KubernetesServiceCatalog); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...netes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-kubernetes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apiVersion: serving.knative.dev/v1 | ||
kind: Service | ||
metadata: | ||
annotations: | ||
serving.knative.dev/creator: minikube-user | ||
serving.knative.dev/lastModifier: minikube-user | ||
creationTimestamp: '2022-08-17T13:58:53Z' | ||
generation: 1 | ||
name: serverless-workflow-greeting-quarkus-kubernetes | ||
resourceVersion: '43817' | ||
uid: 98530cb6-3274-4d0c-b654-a82645cda058 | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z' | ||
client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0 | ||
creationTimestamp: | ||
spec: | ||
containerConcurrency: 0 | ||
containers: | ||
- image: kiegroup/serverless-workflow-greeting-quarkus:1.0 | ||
name: user-container | ||
readinessProbe: | ||
successThreshold: 1 | ||
tcpSocket: | ||
port: 0 | ||
resources: { } | ||
enableServiceLinks: false | ||
timeoutSeconds: 300 | ||
traffic: | ||
- latestRevision: true | ||
percent: 100 | ||
status: | ||
address: | ||
url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local | ||
conditions: | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: ConfigurationsReady | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: Ready | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: RoutesReady | ||
latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001 | ||
latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001 | ||
observedGeneration: 1 | ||
traffic: | ||
- latestRevision: true | ||
percent: 100 | ||
revisionName: serverless-workflow-greeting-quarkus-00001 | ||
url: http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io |
54 changes: 54 additions & 0 deletions
54
...rnetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-openshift.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apiVersion: serving.knative.dev/v1 | ||
kind: Service | ||
metadata: | ||
annotations: | ||
serving.knative.dev/creator: minikube-user | ||
serving.knative.dev/lastModifier: minikube-user | ||
creationTimestamp: '2022-08-17T13:58:53Z' | ||
generation: 1 | ||
name: serverless-workflow-greeting-quarkus-openshift | ||
resourceVersion: '43817' | ||
uid: 98530cb6-3274-4d0c-b654-a82645cda058 | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z' | ||
client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0 | ||
creationTimestamp: | ||
spec: | ||
containerConcurrency: 0 | ||
containers: | ||
- image: kiegroup/serverless-workflow-greeting-quarkus:1.0 | ||
name: user-container | ||
readinessProbe: | ||
successThreshold: 1 | ||
tcpSocket: | ||
port: 0 | ||
resources: { } | ||
enableServiceLinks: false | ||
timeoutSeconds: 300 | ||
traffic: | ||
- latestRevision: true | ||
percent: 100 | ||
status: | ||
address: | ||
url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local | ||
conditions: | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: ConfigurationsReady | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: Ready | ||
- lastTransitionTime: '2022-08-17T13:59:00Z' | ||
status: 'True' | ||
type: RoutesReady | ||
latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001 | ||
latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001 | ||
observedGeneration: 1 | ||
traffic: | ||
- latestRevision: true | ||
percent: 100 | ||
revisionName: serverless-workflow-greeting-quarkus-00001 | ||
url: http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.