fix tests & introduce run/test configurations "test" (without tag containertest) and "testall" (incl. tag containertest)
This commit is contained in:
parent
fbac808491
commit
b3b98d8a2b
5 changed files with 95 additions and 8 deletions
|
@ -49,7 +49,7 @@ test:
|
|||
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
|
||||
- docker run --privileged -dit --name provs_test -v /var/run/docker.sock:/var/run/docker.sock $CI_REGISTRY_IMAGE
|
||||
- docker inspect -f '{{.State.Running}}' provs_test
|
||||
- ./gradlew test -Dtestdockerwithoutsudo=true
|
||||
- ./gradlew test -Dtestdockerwithoutsudo=true -DexcludeTags=containertest
|
||||
artifacts:
|
||||
when: on_failure
|
||||
paths:
|
||||
|
|
14
.run/test.run.xml
Normal file
14
.run/test.run.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="test" type="JUnit" factoryName="JUnit">
|
||||
<module name="provs.test" />
|
||||
<option name="PACKAGE_NAME" value="org" />
|
||||
<option name="MAIN_CLASS_NAME" value="" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="tags" />
|
||||
<option name="VM_PARAMETERS" value="-DexcludeTags="containertest"" />
|
||||
<tag value="!containertest" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
13
.run/testall.run.xml
Normal file
13
.run/testall.run.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="testall" type="JUnit" factoryName="JUnit">
|
||||
<module name="provs.test" />
|
||||
<option name="PACKAGE_NAME" value="org" />
|
||||
<option name="MAIN_CLASS_NAME" value="" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="package" />
|
||||
<option name="VM_PARAMETERS" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
|
@ -4,17 +4,17 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
|||
import org.domaindrivenarchitecture.provs.framework.core.docker.containerRuns
|
||||
import org.domaindrivenarchitecture.provs.framework.core.docker.exitAndRmContainer
|
||||
import org.domaindrivenarchitecture.provs.framework.core.docker.runContainer
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
import org.domaindrivenarchitecture.provs.test.tags.NonCi
|
||||
import org.domaindrivenarchitecture.provs.test.testLocal
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
||||
internal class UbuntuHostDockerKtTest {
|
||||
|
||||
@Test
|
||||
@NonCi
|
||||
@ContainerTest
|
||||
fun runAndCheckAndExitContainer() {
|
||||
// when
|
||||
val containerName = "testContainer"
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.docker
|
||||
import org.domaindrivenarchitecture.provs.framework.core.*
|
||||
import org.domaindrivenarchitecture.provs.framework.core.docker.containerExec
|
||||
import org.domaindrivenarchitecture.provs.framework.core.docker.provideContainer
|
||||
import org.domaindrivenarchitecture.provs.framework.core.local
|
||||
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
|
||||
import org.domaindrivenarchitecture.provs.server.apple.appleConfig
|
||||
import org.domaindrivenarchitecture.provs.server.apple.checkAppleService
|
||||
import org.domaindrivenarchitecture.provs.server.domain.applyK8sConfig
|
||||
import org.domaindrivenarchitecture.provs.server.domain.installK3sAsContainers
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
|
@ -53,7 +50,6 @@ internal class K3dKtTest {
|
|||
""".trimIndent())
|
||||
}
|
||||
|
||||
|
||||
// when
|
||||
installK3sAsContainers()
|
||||
applyK8sConfig(appleConfig())
|
||||
|
@ -66,3 +62,67 @@ internal class K3dKtTest {
|
|||
assertTrue(result.success)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if URL "$host/apple" is available and return text "apple"
|
||||
*/
|
||||
private fun Prov.checkAppleService(host: String = "127.0.0.1") = requireLast {
|
||||
// repeat required as curl may return with "empty reply from server" or with "Recv failure: Connection reset by peer"
|
||||
val res = repeatTaskUntilSuccess(12, 10) {
|
||||
cmd("curl -m 30 $host/apple")
|
||||
}.out?.trim()
|
||||
|
||||
if ("apple" == res) {
|
||||
ProvResult(true, out = res)
|
||||
} else {
|
||||
ProvResult(false, err = "Url $host/apple did not return text \"apple\" but returned: $res")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun appleConfig() =
|
||||
"""
|
||||
kind: Ingress
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: apple-ingress
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "traefik"
|
||||
spec:
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /apple
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: apple-service
|
||||
port:
|
||||
number: 5678
|
||||
---
|
||||
|
||||
kind: Pod
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: apple-app
|
||||
labels:
|
||||
app: apple
|
||||
spec:
|
||||
containers:
|
||||
- name: apple-app
|
||||
image: hashicorp/http-echo
|
||||
args:
|
||||
- "-text=apple"
|
||||
---
|
||||
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: apple-service
|
||||
spec:
|
||||
selector:
|
||||
app: apple
|
||||
ports:
|
||||
- port: 5678 # Default port for image
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue