From 8f876c138e4c61802cd303f2d5a0b8b861a1be61 Mon Sep 17 00:00:00 2001 From: jerger Date: Tue, 5 Jul 2022 20:38:49 +0200 Subject: [PATCH] fix tests --- .../desktop/infrastructure/k3s-connect.sh | 11 ++++++++--- .../infrastructure/k3s-create-context.sh | 12 +++++++++--- .../desktop/infrastructure/k8s-connect.sh | 11 ++++++++--- .../infrastructure/k8s-create-context.sh | 12 +++++++++--- .../desktop/application/ApplicationKtTest.kt | 18 ++++++++---------- .../desktop/domain/DesktopServiceKtTest.kt | 12 ++++++++---- 6 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh index 9975104..15c8b98 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh @@ -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 diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh index 4e5e6a3..18a5903 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh @@ -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 diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh index f01ece7..cf9d2a3 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh @@ -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 diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh index 3a16eac..709d124 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh @@ -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 diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt index 3c75643..aa0954b 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/ApplicationKtTest.kt @@ -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().provisionDesktop(any(), any(), any(), any(), any(), ) } returns ProvResult( + mockkStatic(Prov::provisionDesktopImpl) + every { any().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().provisionDesktop( + any().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().provisionDesktop(any(), any(), any(), any(), any(), ) } + verify(exactly = 0) { any().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().provisionDesktop(any(), any(), any(), any(), any(), ) } + verify(exactly = 0) { any().provisionDesktopImpl(any(), any(), any(), any(), any(), any()) } } } \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt index 6fe4fc5..9791543 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopServiceKtTest.kt @@ -17,10 +17,11 @@ internal class DesktopServiceKtTest { // when val exception = assertThrows { - 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