From b3b98d8a2b3bb7f273385da874c8e703280919dd Mon Sep 17 00:00:00 2001 From: ansgarz Date: Sun, 30 Jan 2022 20:00:09 +0100 Subject: [PATCH] fix tests & introduce run/test configurations "test" (without tag containertest) and "testall" (incl. tag containertest) --- .gitlab-ci.yml | 2 +- .run/test.run.xml | 14 ++++ .run/testall.run.xml | 13 ++++ .../platforms/UbuntuHostDockerKtTest.kt | 4 +- .../provs/server/infrastructure/K3dKtTest.kt | 70 +++++++++++++++++-- 5 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 .run/test.run.xml create mode 100644 .run/testall.run.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 44bcba1..e45b1a9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/.run/test.run.xml b/.run/test.run.xml new file mode 100644 index 0000000..fa20242 --- /dev/null +++ b/.run/test.run.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/.run/testall.run.xml b/.run/testall.run.xml new file mode 100644 index 0000000..e24ff1e --- /dev/null +++ b/.run/testall.run.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt index 44de8d2..15736b7 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt @@ -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" diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3dKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3dKtTest.kt index 6974650..1fc19fe 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3dKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3dKtTest.kt @@ -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 + """