forked from dekorateio/dekorate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Probe tests from
examples
to tests
In this PR: dekorateio#875, we added the Probe coverage under the examples, where it should go under the tests modules.
- Loading branch information
Showing
20 changed files
with
588 additions
and
154 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
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
8 changes: 1 addition & 7 deletions
8
examples/vertx-on-kubernetes-example/src/main/resources/application.properties
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
dekorate.kubernetes.ports[0].name=http | ||
dekorate.kubernetes.ports[0].containerPort=8080 | ||
dekorate.kubernetes.readinessProbe.httpActionPath=/readiness | ||
dekorate.kubernetes.readinessProbe.httpActionPath=/ | ||
dekorate.kubernetes.readinessProbe.periodSeconds=30 | ||
dekorate.kubernetes.readinessProbe.timeoutSeconds=10 | ||
dekorate.kubernetes.livenessProbe.httpActionPath=/liveness | ||
dekorate.kubernetes.livenessProbe.periodSeconds=31 | ||
dekorate.kubernetes.livenessProbe.timeoutSeconds=11 | ||
dekorate.kubernetes.startupProbe.httpActionPath=/startup | ||
dekorate.kubernetes.startupProbe.periodSeconds=32 | ||
dekorate.kubernetes.startupProbe.timeoutSeconds=12 |
53 changes: 6 additions & 47 deletions
53
examples/vertx-on-kubernetes-example/src/test/java/io/dekorate/example/VertxTest.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 |
---|---|---|
@@ -1,80 +1,39 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* | ||
* 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 io.dekorate.example; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.KubernetesList; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.Probe; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static io.dekorate.testing.KubernetesResources.*; | ||
|
||
class VertxTest { | ||
|
||
@Test | ||
public void shouldContainService() { | ||
public void shouldContainService() throws Exception { | ||
KubernetesList list = loadGenerated("kubernetes"); | ||
Optional<Service> service = findFirst(list, Service.class); | ||
assertTrue(service.isPresent()); | ||
} | ||
|
||
@Test | ||
public void shouldContainProbes() { | ||
KubernetesList list = loadGenerated("kubernetes"); | ||
Optional<Deployment> deployment = findFirst(list, Deployment.class); | ||
assertTrue(deployment.isPresent(), "Deployment not found!"); | ||
|
||
assertReadinessProbe(deployment.get(), "/readiness", 30, 10); | ||
assertLivenessProbe(deployment.get(), "/liveness", 31, 11); | ||
assertStartupProbe(deployment.get(), "/startup", 32, 12); | ||
} | ||
|
||
private static void assertReadinessProbe(Deployment deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getReadinessProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertLivenessProbe(Deployment deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getLivenessProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertStartupProbe(Deployment deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getStartupProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertProbe(Deployment deployment, | ||
Function<Container, Probe> probeFunction, | ||
String actionPath, int periodSeconds, int timeoutSeconds) { | ||
|
||
assertTrue(deployment.getSpec().getTemplate().getSpec().getContainers().stream() | ||
.map(probeFunction) | ||
.anyMatch(probe -> actionPath.equals(probe.getHttpGet().getPath()) | ||
&& periodSeconds == probe.getPeriodSeconds() && timeoutSeconds == probe.getTimeoutSeconds())); | ||
} | ||
} | ||
|
8 changes: 1 addition & 7 deletions
8
examples/vertx-on-openshift-example/src/main/resources/application.properties
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
dekorate.openshift.ports[0].name=http | ||
dekorate.openshift.ports[0].containerPort=8080 | ||
dekorate.openshift.readinessProbe.httpActionPath=/readiness | ||
dekorate.openshift.readinessProbe.httpActionPath=/ | ||
dekorate.openshift.readinessProbe.periodSeconds=30 | ||
dekorate.openshift.readinessProbe.timeoutSeconds=10 | ||
dekorate.openshift.livenessProbe.httpActionPath=/liveness | ||
dekorate.openshift.livenessProbe.periodSeconds=31 | ||
dekorate.openshift.livenessProbe.timeoutSeconds=11 | ||
dekorate.openshift.startupProbe.httpActionPath=/startup | ||
dekorate.openshift.startupProbe.periodSeconds=32 | ||
dekorate.openshift.startupProbe.timeoutSeconds=12 |
53 changes: 6 additions & 47 deletions
53
examples/vertx-on-openshift-example/src/test/java/io/dekorate/example/VertxTest.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 |
---|---|---|
@@ -1,80 +1,39 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* | ||
* 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 io.dekorate.example; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.api.model.Container; | ||
import io.fabric8.kubernetes.api.model.KubernetesList; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.Probe; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.openshift.api.model.DeploymentConfig; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static io.dekorate.testing.KubernetesResources.*; | ||
|
||
class VertxTest { | ||
|
||
@Test | ||
public void shouldContainService() { | ||
public void shouldContainService() throws Exception { | ||
KubernetesList list = loadGenerated("openshift"); | ||
Optional<Service> service = findFirst(list, Service.class); | ||
assertTrue(service.isPresent()); | ||
} | ||
|
||
@Test | ||
public void shouldContainProbes() { | ||
KubernetesList list = loadGenerated("openshift"); | ||
Optional<DeploymentConfig> deployment = findFirst(list, DeploymentConfig.class); | ||
assertTrue(deployment.isPresent(), "DeploymentConfig not found!"); | ||
|
||
assertReadinessProbe(deployment.get(), "/readiness", 30, 10); | ||
assertLivenessProbe(deployment.get(), "/liveness", 31, 11); | ||
assertStartupProbe(deployment.get(), "/startup", 32, 12); | ||
} | ||
|
||
private static void assertReadinessProbe(DeploymentConfig deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getReadinessProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertLivenessProbe(DeploymentConfig deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getLivenessProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertStartupProbe(DeploymentConfig deployment, String actionPath, | ||
int periodSeconds, int timeoutSeconds) { | ||
assertProbe(deployment, Container::getStartupProbe, actionPath, periodSeconds, timeoutSeconds); | ||
} | ||
|
||
private static void assertProbe(DeploymentConfig deployment, | ||
Function<Container, Probe> probeFunction, | ||
String actionPath, int periodSeconds, int timeoutSeconds) { | ||
|
||
assertTrue(deployment.getSpec().getTemplate().getSpec().getContainers().stream() | ||
.map(probeFunction) | ||
.anyMatch(probe -> actionPath.equals(probe.getHttpGet().getPath()) | ||
&& periodSeconds == probe.getPeriodSeconds() && timeoutSeconds == probe.getTimeoutSeconds())); | ||
} | ||
} | ||
|
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
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,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2018 The original authors. | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>dekorate-tests</artifactId> | ||
<groupId>io.dekorate</groupId> | ||
<version>2.9-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
|
||
<groupId>io.dekorate</groupId> | ||
<version>2.9-SNAPSHOT</version> | ||
<artifactId>feat-probes-knative</artifactId> | ||
<name>Dekorate :: Tests :: Probes :: Knative</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>knative-annotations</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>dekorate-spring-boot</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${version.spring-boot}</version> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>io.dekorate</groupId> | ||
<artifactId>knative-junit-starter</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
tests/feat-knative-probes/src/main/java/io/dekorate/example/Controller.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,28 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* 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 io.dekorate.example; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class Controller { | ||
|
||
@RequestMapping("/") | ||
public String hello() { | ||
return "Hello world"; | ||
} | ||
} |
Oops, something went wrong.