@ -7,7 +7,7 @@ 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.provision Workplace
import org.domaindrivenarchitecture.provs.desktop.domain.provision Desktop
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.*
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword
@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test
import java.io.ByteArrayOutputStream
import java.io.PrintStream
internal class CliWorkplace KtTest {
internal class Application KtTest {
companion object {
@ -31,6 +31,7 @@ internal class CliWorkplaceKtTest {
ConfigFileName ( " bla " )
)
@Suppress ( " unused " ) // false positive
@BeforeAll
@JvmStatic
internal fun beforeAll ( ) {
@ -48,8 +49,8 @@ internal class CliWorkplaceKtTest {
mockkStatic ( :: getConfig )
every { getConfig ( " testconfig.yaml " ) } returns testConfig
mockkStatic ( Prov :: provision Workplace )
every { any < Prov > ( ) . provision Workplace ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) } returns ProvResult (
mockkStatic ( Prov :: provision Desktop )
every { any < Prov > ( ) . provision Desktop ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) } returns ProvResult (
true ,
cmd = " mocked command "
)
@ -58,6 +59,7 @@ internal class CliWorkplaceKtTest {
every { retrievePassword ( any ( ) ) } returns Secret ( " sec " )
}
@Suppress ( " unused " ) // false positive
@AfterAll
@JvmStatic
internal fun afterAll ( ) {
@ -65,13 +67,13 @@ internal class CliWorkplaceKtTest {
unmockkStatic ( :: local )
unmockkStatic ( :: remote )
unmockkStatic ( :: getConfig )
unmockkStatic ( Prov :: provision Workplace )
unmockkStatic ( Prov :: provision Desktop )
unmockkStatic ( :: retrievePassword )
}
}
@Test
fun provision _ workplace _remotely ( ) {
fun provision _ desktop _remotely ( ) {
// when
main ( arrayOf ( " basic " , " user123:sec@host123.xyz " , " -c " , " testconfig.yaml " ) )
@ -79,7 +81,7 @@ internal class CliWorkplaceKtTest {
// then
verify { remote ( " host123.xyz " , " user123 " , Secret ( " sec " ) , any ( ) ) }
verify {
any < Prov > ( ) . provision Workplace (
any < Prov > ( ) . provision Desktop (
DesktopType . BASIC ,
null ,
null ,
@ -110,10 +112,10 @@ internal class CliWorkplaceKtTest {
System . setErr ( originalErr )
val expectedOutput =
" Error: File \u001B [31m idontexist.yaml \u001B [0m was not found.Pls copy file \u001B [31m WorkplaceConfigE xample.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-e xample.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 > ( ) . provision Workplace ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) }
verify ( exactly = 0 ) { any < Prov > ( ) . provision Desktop ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) }
}
@Test
@ -130,16 +132,16 @@ internal class CliWorkplaceKtTest {
System . setErr ( PrintStream ( errContent ) )
// when
main ( arrayOf ( " basic " , " someuser@remotehost " , " -c " , " src/test/resources/ InvalidWorkplaceC onfig.yaml" ) )
main ( arrayOf ( " basic " , " someuser@remotehost " , " -c " , " src/test/resources/ invalid-desktop-c onfig.yaml" ) )
// then
System . setOut ( originalOut )
System . setErr ( originalErr )
val expectedOutput =
" Error: File \" src/test/resources/ InvalidWorkplaceC onfig.yaml\" has an invalid format and or invalid data. "
" Error: File \" src/test/resources/ invalid-desktop-c onfig.yaml\" has an invalid format and or invalid data. "
assertEquals ( expectedOutput , outContent . toString ( ) . replace ( " \r " , " " ) . replace ( " \n " , " " ) )
verify ( exactly = 0 ) { any < Prov > ( ) . provision Workplace ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) }
verify ( exactly = 0 ) { any < Prov > ( ) . provision Desktop ( any ( ) , any ( ) , any ( ) , any ( ) , any ( ) , ) }
}
}