refactor & fix execution of onlyModules, add tests
This commit is contained in:
parent
f4da33dcb5
commit
9ceb74515d
6 changed files with 163 additions and 102 deletions
|
@ -2,4 +2,9 @@ package org.domaindrivenarchitecture.provs.desktop.domain
|
||||||
|
|
||||||
enum class DesktopOnlyModule {
|
enum class DesktopOnlyModule {
|
||||||
FIREFOX, VERIFY
|
FIREFOX, VERIFY
|
||||||
|
;
|
||||||
|
|
||||||
|
fun isIn(list: List<String>): Boolean {
|
||||||
|
return list.any { it.equals(this.name, ignoreCase = true) }
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.domaindrivenarchitecture.provs.desktop.domain
|
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopOnlyModule.FIREFOX
|
||||||
|
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopOnlyModule.VERIFY
|
||||||
import org.domaindrivenarchitecture.provs.desktop.infrastructure.*
|
import org.domaindrivenarchitecture.provs.desktop.infrastructure.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.git.provisionGit
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.git.provisionGit
|
||||||
|
@ -42,21 +44,29 @@ internal fun Prov.provisionDesktop(
|
||||||
onlyModules: List<String>?
|
onlyModules: List<String>?
|
||||||
) = task {
|
) = task {
|
||||||
validatePrecondition()
|
validatePrecondition()
|
||||||
provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail, onlyModules)
|
|
||||||
|
if (onlyModules == null) {
|
||||||
|
provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail)
|
||||||
|
|
||||||
if (desktopType == DesktopType.OFFICE) {
|
if (desktopType == DesktopType.OFFICE) {
|
||||||
provisionOfficeDesktop(onlyModules)
|
provisionOfficeDesktop()
|
||||||
if (onlyModules == null) {
|
|
||||||
verifyOfficeSetup()
|
verifyOfficeSetup()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (desktopType == DesktopType.IDE) {
|
if (desktopType == DesktopType.IDE) {
|
||||||
if (onlyModules == null) {
|
|
||||||
provisionOfficeDesktop()
|
provisionOfficeDesktop()
|
||||||
provisionIdeDesktop()
|
provisionIdeDesktop()
|
||||||
verifyIdeSetup()
|
verifyIdeSetup()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
provisionIdeDesktop(onlyModules)
|
if (FIREFOX.isIn(onlyModules)) {
|
||||||
|
installPpaFirefox()
|
||||||
|
}
|
||||||
|
if (VERIFY.isIn(onlyModules)) {
|
||||||
|
if (desktopType == DesktopType.OFFICE) {
|
||||||
|
verifyOfficeSetup()
|
||||||
|
} else if (desktopType == DesktopType.IDE) {
|
||||||
|
verifyIdeSetup()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,61 +77,13 @@ fun Prov.validatePrecondition() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Prov.provisionIdeDesktop(onlyModules: List<String>? = null) {
|
|
||||||
if (onlyModules == null) {
|
|
||||||
aptInstall(OPEN_VPM)
|
|
||||||
aptInstall(OPENCONNECT)
|
|
||||||
aptInstall(VPNC)
|
|
||||||
|
|
||||||
// DevEnvs
|
|
||||||
installDocker()
|
|
||||||
aptInstall(JAVA)
|
|
||||||
aptInstall(CLOJURE_TOOLS)
|
|
||||||
installShadowCljs()
|
|
||||||
installDevOps()
|
|
||||||
provisionPython()
|
|
||||||
|
|
||||||
// IDEs
|
|
||||||
installVSC("python", "clojure")
|
|
||||||
installIntelliJ()
|
|
||||||
} else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
|
|
||||||
verifyIdeSetup()
|
|
||||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
|
||||||
installPpaFirefox()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Prov.provisionOfficeDesktop(onlyModules: List<String>? = null) {
|
|
||||||
if (onlyModules == null) {
|
|
||||||
aptInstall(ZIP_UTILS)
|
|
||||||
aptInstall(SPELLCHECKING_DE)
|
|
||||||
aptInstall(BROWSER)
|
|
||||||
aptInstall(EMAIL_CLIENT)
|
|
||||||
installDeltaChat()
|
|
||||||
aptInstall(OFFICE_SUITE)
|
|
||||||
installZimWiki()
|
|
||||||
installNextcloudClient()
|
|
||||||
aptInstall(COMPARE_TOOLS)
|
|
||||||
|
|
||||||
// optional as installation of these tools often fail and they are not considered mandatory
|
|
||||||
optional {
|
|
||||||
aptInstall(DRAWING_TOOLS)
|
|
||||||
}
|
|
||||||
} else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
|
|
||||||
verifyOfficeSetup()
|
|
||||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
|
||||||
installPpaFirefox()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Prov.provisionBasicDesktop(
|
fun Prov.provisionBasicDesktop(
|
||||||
gpg: KeyPair?,
|
gpg: KeyPair?,
|
||||||
ssh: SshKeyPair?,
|
ssh: SshKeyPair?,
|
||||||
gitUserName: String?,
|
gitUserName: String?,
|
||||||
gitEmail: String?,
|
gitEmail: String?,
|
||||||
onlyModules: List<String>?
|
|
||||||
) {
|
) {
|
||||||
if (onlyModules == null) {
|
|
||||||
aptInstall(KEY_MANAGEMENT)
|
aptInstall(KEY_MANAGEMENT)
|
||||||
aptInstall(VERSION_MANAGEMENT)
|
aptInstall(VERSION_MANAGEMENT)
|
||||||
aptInstall(NETWORK_TOOLS)
|
aptInstall(NETWORK_TOOLS)
|
||||||
|
@ -153,7 +115,40 @@ fun Prov.provisionBasicDesktop(
|
||||||
configureNoSwappiness()
|
configureNoSwappiness()
|
||||||
configureBash()
|
configureBash()
|
||||||
installVirtualBoxGuestAdditions()
|
installVirtualBoxGuestAdditions()
|
||||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
}
|
||||||
installPpaFirefox()
|
|
||||||
|
fun Prov.provisionOfficeDesktop() {
|
||||||
|
aptInstall(ZIP_UTILS)
|
||||||
|
aptInstall(SPELLCHECKING_DE)
|
||||||
|
aptInstall(BROWSER)
|
||||||
|
aptInstall(EMAIL_CLIENT)
|
||||||
|
installDeltaChat()
|
||||||
|
aptInstall(OFFICE_SUITE)
|
||||||
|
installZimWiki()
|
||||||
|
installNextcloudClient()
|
||||||
|
aptInstall(COMPARE_TOOLS)
|
||||||
|
|
||||||
|
// optional, as installation of these tools often fail and as they are not considered mandatory
|
||||||
|
optional {
|
||||||
|
aptInstall(DRAWING_TOOLS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Prov.provisionIdeDesktop() {
|
||||||
|
aptInstall(OPEN_VPM)
|
||||||
|
aptInstall(OPENCONNECT)
|
||||||
|
aptInstall(VPNC)
|
||||||
|
|
||||||
|
// DevEnvs
|
||||||
|
installDocker()
|
||||||
|
aptInstall(JAVA)
|
||||||
|
aptInstall(CLOJURE_TOOLS)
|
||||||
|
installShadowCljs()
|
||||||
|
installDevOps()
|
||||||
|
provisionPython()
|
||||||
|
|
||||||
|
// IDEs
|
||||||
|
installVSC("python", "clojure")
|
||||||
|
installIntelliJ()
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.domaindrivenarchitecture.provs.configuration.application
|
||||||
|
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockkStatic
|
import io.mockk.mockkStatic
|
||||||
import io.mockk.unmockkStatic
|
import io.mockk.unmockkAll
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.*
|
import org.domaindrivenarchitecture.provs.framework.core.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.cli.getPasswordToConfigureSudoWithoutPassword
|
import org.domaindrivenarchitecture.provs.framework.core.cli.getPasswordToConfigureSudoWithoutPassword
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.docker.provideContainer
|
import org.domaindrivenarchitecture.provs.framework.core.docker.provideContainer
|
||||||
|
@ -49,7 +49,8 @@ class ProvWithSudoKtTest {
|
||||||
assertFalse(canSudo1)
|
assertFalse(canSudo1)
|
||||||
assertTrue(canSudo2)
|
assertTrue(canSudo2)
|
||||||
|
|
||||||
unmockkStatic(::getPasswordToConfigureSudoWithoutPassword)
|
// cleanup
|
||||||
|
unmockkAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExtensiveContainerTest
|
@ExtensiveContainerTest
|
||||||
|
|
|
@ -31,10 +31,8 @@ internal class TargetCliCommandKtTest {
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
internal fun afterAll() {
|
internal fun afterAll() {
|
||||||
unmockkObject(Prov)
|
// cleanup
|
||||||
unmockkStatic(::local)
|
unmockkAll()
|
||||||
unmockkStatic(::remote)
|
|
||||||
unmockkStatic(::getPasswordToConfigureSudoWithoutPassword)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,8 @@ internal class ApplicationKtTest {
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
internal fun afterAll() {
|
internal fun afterAll() {
|
||||||
unmockkObject(Prov)
|
// cleanup
|
||||||
unmockkStatic(::local)
|
unmockkAll()
|
||||||
unmockkStatic(::remote)
|
|
||||||
unmockkStatic(::getConfig)
|
|
||||||
unmockkStatic(Prov::provisionDesktop)
|
|
||||||
unmockkStatic(::getPasswordToConfigureSudoWithoutPassword)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package org.domaindrivenarchitecture.provs.desktop.domain
|
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.ProgressType
|
import io.mockk.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.desktop.infrastructure.installPpaFirefox
|
||||||
|
import org.domaindrivenarchitecture.provs.desktop.infrastructure.verifyIdeSetup
|
||||||
|
import org.domaindrivenarchitecture.provs.desktop.infrastructure.verifyOfficeSetup
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.docker.provideContainer
|
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.framework.core.processors.ContainerStartMode
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerUbuntuHostProcessor
|
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerUbuntuHostProcessor
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.remote
|
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.deleteFile
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.deleteFile
|
||||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
||||||
|
@ -44,6 +46,70 @@ internal class DesktopServiceKtTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun provisionDesktop_with_onlyModules_firefox_installs_firefox() {
|
||||||
|
// given
|
||||||
|
val prov = Prov.newInstance(DummyProcessor())
|
||||||
|
mockkStatic(Prov::installPpaFirefox) // mocks all function in file Firefox.kt
|
||||||
|
every { any<Prov>().installPpaFirefox() } returns ProvResult(true, cmd = "mocked")
|
||||||
|
|
||||||
|
// when
|
||||||
|
prov.provisionDesktop(DesktopType.IDE, onlyModules = listOf("firefox"))
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(exactly = 1) { any<Prov>().installPpaFirefox() }
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
unmockkAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun provisionDesktop_ide_with_onlyModules_verify_performs_verification() {
|
||||||
|
// given
|
||||||
|
val prov = Prov.newInstance(DummyProcessor())
|
||||||
|
mockkStatic(Prov::verifyIdeSetup)
|
||||||
|
mockkStatic(Prov::verifyOfficeSetup)
|
||||||
|
mockkStatic(Prov::provisionBasicDesktop) // mocks function provisionBasicDesktop and all other functions in same file
|
||||||
|
every { any<Prov>().verifyIdeSetup() } returns ProvResult(true, cmd = "mocked")
|
||||||
|
every { any<Prov>().verifyOfficeSetup() } returns ProvResult(true, cmd = "mocked")
|
||||||
|
every { any<Prov>().provisionBasicDesktop(any(), any(), any(), any()) }
|
||||||
|
|
||||||
|
// when
|
||||||
|
prov.provisionDesktop(DesktopType.IDE, onlyModules = listOf("verify"))
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(exactly = 1) { any<Prov>().verifyIdeSetup() }
|
||||||
|
verify(exactly = 0) { any<Prov>().verifyOfficeSetup() }
|
||||||
|
verify(exactly = 0) { any<Prov>().provisionBasicDesktop(any(), any(), any(), any()) }
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
unmockkAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun provisionDesktop_office_with_onlyModules_verify_performs_verification() {
|
||||||
|
// given
|
||||||
|
val prov = Prov.newInstance(DummyProcessor())
|
||||||
|
mockkStatic(Prov::verifyIdeSetup)
|
||||||
|
mockkStatic(Prov::verifyOfficeSetup)
|
||||||
|
mockkStatic(Prov::provisionBasicDesktop)
|
||||||
|
every { any<Prov>().verifyIdeSetup() } returns ProvResult(true, cmd = "mocked")
|
||||||
|
every { any<Prov>().verifyOfficeSetup() } returns ProvResult(true, cmd = "mocked")
|
||||||
|
every { any<Prov>().provisionBasicDesktop(any(), any(), any(), any()) }
|
||||||
|
|
||||||
|
// when
|
||||||
|
prov.provisionDesktop(DesktopType.OFFICE, onlyModules = listOf("verify"))
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(exactly = 0) { any<Prov>().verifyIdeSetup() }
|
||||||
|
verify(exactly = 1) { any<Prov>().verifyOfficeSetup() }
|
||||||
|
verify(exactly = 0) { any<Prov>().provisionBasicDesktop(any(), any(), any(), any()) }
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
unmockkAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ExtensiveContainerTest
|
@ExtensiveContainerTest
|
||||||
@Disabled("Takes very long, enable if you want to test a desktop setup")
|
@Disabled("Takes very long, enable if you want to test a desktop setup")
|
||||||
fun provisionDesktop() {
|
fun provisionDesktop() {
|
||||||
|
|
Loading…
Reference in a new issue