fix tests

This commit is contained in:
jerger 2022-07-05 20:38:49 +02:00
parent 5b99f3828c
commit 8f876c138e
6 changed files with 50 additions and 26 deletions

View file

@ -2,18 +2,23 @@
set -e set -e
set -o noglob set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() { function main() {
local cluster_name="${1}"; shift local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
/usr/local/bin/k3s-create-context.sh ${cluster_name} /usr/local/bin/k3s-create-context.sh ${cluster_name}
kubectl config use-context ${cluster_name} kubectl config use-context ${cluster_name}
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} -L 8002:localhost:8002 -L 6443:192.168.5.1:6443
} }
if [ $# -eq 1 ] if [ $# -gt 0 ]
then then
main $1 main $1
else else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" usage
exit -1 exit -1
fi fi

View file

@ -2,10 +2,16 @@
set -e set -e
set -o noglob set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() { function main() {
local cluster_name="${1}"; shift local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de \ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} \
"cat /etc/rancher/k3s/k3s.yaml" | \ "cat /etc/rancher/k3s/k3s.yaml" | \
yq e ".clusters[0].name=\"${cluster_name}\" \ yq e ".clusters[0].name=\"${cluster_name}\" \
| .clusters[0].cluster.server=\"https://kubernetes:6443\" \ | .clusters[0].cluster.server=\"https://kubernetes:6443\" \
@ -18,10 +24,10 @@ function main() {
> ~/.kube/custom-contexts/${cluster_name}.yml > ~/.kube/custom-contexts/${cluster_name}.yml
} }
if [ $# -eq 1 ] if [ $# -gt 0 ]
then then
main $1 main $1
else else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" usage
exit -1 exit -1
fi fi

View file

@ -2,18 +2,23 @@
set -e set -e
set -o noglob set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() { function main() {
local cluster_name="${1}"; shift local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
/usr/local/bin/k8s-create-context.sh ${cluster_name} /usr/local/bin/k8s-create-context.sh ${cluster_name}
kubectl config use-context ${cluster_name} kubectl config use-context ${cluster_name}
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} -L 8002:localhost:8002 -L 6443:192.168.5.1:6443
} }
if [ $# -eq 1 ] if [ $# -gt 0 ]
then then
main $1 main $1
else else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" usage
exit -1 exit -1
fi fi

View file

@ -2,10 +2,16 @@
set -e set -e
set -o noglob set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() { function main() {
local cluster_name="${1}"; shift local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de \ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} \
"cat /etc/kubernetes/admin.conf" | \ "cat /etc/kubernetes/admin.conf" | \
yq e ".clusters[0].name=\"${cluster_name}\" \ yq e ".clusters[0].name=\"${cluster_name}\" \
| .clusters[0].cluster.server=\"https://kubernetes:6443\" \ | .clusters[0].cluster.server=\"https://kubernetes:6443\" \
@ -18,10 +24,10 @@ function main() {
> ~/.kube/custom-contexts/${cluster_name}.yml > ~/.kube/custom-contexts/${cluster_name}.yml
} }
if [ $# -eq 1 ] if [ $# -gt 0 ]
then then
main $1 main $1
else else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" usage
exit -1 exit -1
fi fi

View file

@ -4,10 +4,7 @@ import ch.qos.logback.classic.Level
import io.mockk.* import io.mockk.*
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopCliCommand import org.domaindrivenarchitecture.provs.desktop.domain.*
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopConfig
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktop
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.* import org.domaindrivenarchitecture.provs.framework.core.*
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword
@ -49,8 +46,8 @@ internal class ApplicationKtTest {
mockkStatic(::getConfig) mockkStatic(::getConfig)
every { getConfig("testconfig.yaml") } returns testConfig every { getConfig("testconfig.yaml") } returns testConfig
mockkStatic(Prov::provisionDesktop) mockkStatic(Prov::provisionDesktopImpl)
every { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) } returns ProvResult( every { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(),any()) } returns ProvResult(
true, true,
cmd = "mocked command" cmd = "mocked command"
) )
@ -67,7 +64,7 @@ internal class ApplicationKtTest {
unmockkStatic(::local) unmockkStatic(::local)
unmockkStatic(::remote) unmockkStatic(::remote)
unmockkStatic(::getConfig) unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionDesktop) unmockkStatic(Prov::provisionDesktopImpl)
unmockkStatic(::retrievePassword) unmockkStatic(::retrievePassword)
} }
} }
@ -81,12 +78,13 @@ internal class ApplicationKtTest {
// then // then
verify { remote("host123.xyz", "user123", Secret("sec"), any()) } verify { remote("host123.xyz", "user123", Secret("sec"), any()) }
verify { verify {
any<Prov>().provisionDesktop( any<Prov>().provisionDesktopImpl(
DesktopType.BASIC, DesktopType.BASIC,
null, null,
null, null,
testConfig.gitUserName, testConfig.gitUserName,
testConfig.gitEmail, testConfig.gitEmail,
null
) )
} }
} }
@ -115,7 +113,7 @@ internal class ApplicationKtTest {
"Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs." "Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) } verify(exactly = 0) { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(), any()) }
} }
@Test @Test
@ -142,6 +140,6 @@ internal class ApplicationKtTest {
"Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data." "Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) } verify(exactly = 0) { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(), any()) }
} }
} }

View file

@ -17,10 +17,11 @@ internal class DesktopServiceKtTest {
// when // when
val exception = assertThrows<RuntimeException> { val exception = assertThrows<RuntimeException> {
prov.provisionDesktop( prov.provisionDesktopImpl(
DesktopType("iamunkown"), DesktopType("iamunkown"),
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
submodules = null
) )
} }
@ -35,10 +36,11 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val res = prov.provisionDesktop( val res = prov.provisionDesktopImpl(
DesktopType.BASIC, DesktopType.BASIC,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
submodules = null
) )
// then // then
@ -52,10 +54,11 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val res = prov.provisionDesktop( val res = prov.provisionDesktopImpl(
DesktopType.IDE, DesktopType.IDE,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
submodules = null
) )
// then // then
@ -71,12 +74,13 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val config = getConfig("src/test/resources/desktop-config-example.json") val config = getConfig("src/test/resources/desktop-config-example.json")
val res = prov.provisionDesktop( val res = prov.provisionDesktopImpl(
DesktopType.BASIC, DesktopType.BASIC,
config.ssh?.keyPair(), config.ssh?.keyPair(),
config.gpg?.keyPair(), config.gpg?.keyPair(),
config.gitUserName, config.gitUserName,
config.gitEmail, config.gitEmail,
submodules = null
) )
// then // then