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 -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() {
local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
/usr/local/bin/k3s-create-context.sh ${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
main $1
else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de"
usage
exit -1
fi

View file

@ -2,10 +2,16 @@
set -e
set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() {
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" | \
yq e ".clusters[0].name=\"${cluster_name}\" \
| .clusters[0].cluster.server=\"https://kubernetes:6443\" \
@ -18,10 +24,10 @@ function main() {
> ~/.kube/custom-contexts/${cluster_name}.yml
}
if [ $# -eq 1 ]
if [ $# -gt 0 ]
then
main $1
else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de"
usage
exit -1
fi

View file

@ -2,18 +2,23 @@
set -e
set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() {
local cluster_name="${1}"; shift
local domain_name="${1:-meissa-gmbh.de}"; shift
/usr/local/bin/k8s-create-context.sh ${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
main $1
else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de"
usage
exit -1
fi

View file

@ -2,10 +2,16 @@
set -e
set -o noglob
function usage() {
echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}"
}
function main() {
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" | \
yq e ".clusters[0].name=\"${cluster_name}\" \
| .clusters[0].cluster.server=\"https://kubernetes:6443\" \
@ -18,10 +24,10 @@ function main() {
> ~/.kube/custom-contexts/${cluster_name}.yml
}
if [ $# -eq 1 ]
if [ $# -gt 0 ]
then
main $1
else
echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de"
usage
exit -1
fi

View file

@ -4,10 +4,7 @@ import ch.qos.logback.classic.Level
import io.mockk.*
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopCliCommand
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.domain.*
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.*
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword
@ -49,8 +46,8 @@ internal class ApplicationKtTest {
mockkStatic(::getConfig)
every { getConfig("testconfig.yaml") } returns testConfig
mockkStatic(Prov::provisionDesktop)
every { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) } returns ProvResult(
mockkStatic(Prov::provisionDesktopImpl)
every { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(),any()) } returns ProvResult(
true,
cmd = "mocked command"
)
@ -67,7 +64,7 @@ internal class ApplicationKtTest {
unmockkStatic(::local)
unmockkStatic(::remote)
unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionDesktop)
unmockkStatic(Prov::provisionDesktopImpl)
unmockkStatic(::retrievePassword)
}
}
@ -81,12 +78,13 @@ internal class ApplicationKtTest {
// then
verify { remote("host123.xyz", "user123", Secret("sec"), any()) }
verify {
any<Prov>().provisionDesktop(
any<Prov>().provisionDesktopImpl(
DesktopType.BASIC,
null,
null,
testConfig.gitUserName,
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."
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
@ -142,6 +140,6 @@ internal class ApplicationKtTest {
"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", ""))
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
val exception = assertThrows<RuntimeException> {
prov.provisionDesktop(
prov.provisionDesktopImpl(
DesktopType("iamunkown"),
gitUserName = "testuser",
gitEmail = "testuser@test.org",
submodules = null
)
}
@ -35,10 +36,11 @@ internal class DesktopServiceKtTest {
// when
// 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,
gitUserName = "testuser",
gitEmail = "testuser@test.org",
submodules = null
)
// then
@ -52,10 +54,11 @@ internal class DesktopServiceKtTest {
// when
// 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,
gitUserName = "testuser",
gitEmail = "testuser@test.org",
submodules = null
)
// then
@ -71,12 +74,13 @@ internal class DesktopServiceKtTest {
// when
// 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 res = prov.provisionDesktop(
val res = prov.provisionDesktopImpl(
DesktopType.BASIC,
config.ssh?.keyPair(),
config.gpg?.keyPair(),
config.gitUserName,
config.gitEmail,
submodules = null
)
// then