v0.8.15 removed Windows support
This commit is contained in:
parent
12b0be4520
commit
ca529b79d5
15 changed files with 39 additions and 172 deletions
|
@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization'
|
|||
|
||||
|
||||
group = 'org.domaindrivenarchitecture.provs'
|
||||
version = '0.8.15-SNAPSHOT'
|
||||
version = '0.8.15'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.domaindrivenarchitecture.provs.core
|
|||
|
||||
import org.domaindrivenarchitecture.provs.core.platforms.SHELL
|
||||
import org.domaindrivenarchitecture.provs.core.platforms.UbuntuProv
|
||||
import org.domaindrivenarchitecture.provs.core.platforms.WinProv
|
||||
import org.domaindrivenarchitecture.provs.core.processors.LocalProcessor
|
||||
import org.domaindrivenarchitecture.provs.core.processors.Processor
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -10,7 +9,7 @@ import org.slf4j.LoggerFactory
|
|||
|
||||
enum class ProgressType { NONE, DOTS, BASIC, FULL_LOG }
|
||||
enum class ResultMode { NONE, LAST, ALL, FAILEXIT }
|
||||
enum class OS { WINDOWS, LINUX }
|
||||
enum class OS { LINUX }
|
||||
|
||||
|
||||
/**
|
||||
|
@ -35,27 +34,24 @@ open class Prov protected constructor(
|
|||
|
||||
private lateinit var defaultProvInstance: Prov
|
||||
|
||||
fun defaultInstance(platform: String? = null): Prov {
|
||||
fun defaultInstance(): Prov {
|
||||
return if (Factory::defaultProvInstance.isInitialized) {
|
||||
defaultProvInstance
|
||||
} else {
|
||||
defaultProvInstance = newInstance(platform = platform, name = "default instance")
|
||||
defaultProvInstance = newInstance(name = "default instance", platform = OS.LINUX)
|
||||
defaultProvInstance
|
||||
}
|
||||
}
|
||||
|
||||
fun newInstance(
|
||||
processor: Processor = LocalProcessor(),
|
||||
platform: String? = null,
|
||||
name: String? = null,
|
||||
progressType: ProgressType = ProgressType.BASIC
|
||||
progressType: ProgressType = ProgressType.BASIC,
|
||||
platform: OS = OS.LINUX
|
||||
): Prov {
|
||||
|
||||
val os = platform ?: System.getProperty("os.name")
|
||||
|
||||
return when {
|
||||
os.toUpperCase().contains(OS.LINUX.name) -> UbuntuProv(processor, name, progressType)
|
||||
os.toUpperCase().contains(OS.WINDOWS.name) -> WinProv(processor, name, progressType)
|
||||
(platform == OS.LINUX) -> UbuntuProv(processor, name, progressType)
|
||||
else -> throw Exception("OS not supported")
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +139,8 @@ open class Prov protected constructor(
|
|||
}
|
||||
|
||||
|
||||
private val NOT_IMPLEMENTED = "Not implemented"
|
||||
|
||||
/**
|
||||
* Executes a command by using the shell.
|
||||
* Be aware: Executing shell commands that incorporate unsanitized input from an untrusted source
|
||||
|
@ -150,7 +148,7 @@ open class Prov protected constructor(
|
|||
* Thus, the use of this method is strongly discouraged in cases where the command string is constructed from external input.
|
||||
*/
|
||||
open fun cmd(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
|
||||
throw Exception("Not implemented")
|
||||
throw Exception(NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,7 +157,7 @@ open class Prov protected constructor(
|
|||
* Attention: only result is NOT logged the executed command still is.
|
||||
*/
|
||||
open fun cmdNoLog(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
|
||||
throw Exception("Not implemented")
|
||||
throw Exception(NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
|
||||
|
@ -168,7 +166,7 @@ open class Prov protected constructor(
|
|||
* Can be used e.g. for checks which might succeed or fail but where failure should not influence overall success
|
||||
*/
|
||||
open fun cmdNoEval(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
|
||||
throw Exception("Not implemented")
|
||||
throw Exception(NOT_IMPLEMENTED)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,14 +69,14 @@ fun local(): Prov {
|
|||
/**
|
||||
* Returns Prov instance for remote host with remote user with provided password.
|
||||
* If password is null, connection is done by ssh-key.
|
||||
* Platform (Linux, Windows) must be provided if different from local platform.
|
||||
* Platform (Linux, etc) must be provided if different from local platform.
|
||||
*/
|
||||
@Api // used by other libraries resp. KotlinScript
|
||||
fun remote(host: String, remoteUser: String, password: Secret? = null, platform: String? = null): Prov {
|
||||
fun remote(host: String, remoteUser: String, password: Secret? = null, platform: OS = OS.LINUX): Prov {
|
||||
require(host.isNotEmpty(), { "Host must not be empty." })
|
||||
require(remoteUser.isNotEmpty(), { "Remote user must not be empty." })
|
||||
|
||||
return Prov.newInstance(RemoteProcessor(InetAddress.getByName(host), remoteUser, password), platform)
|
||||
return Prov.newInstance(RemoteProcessor(InetAddress.getByName(host), remoteUser, password), platform = platform)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ open class LocalProcessor : Processor {
|
|||
@Suppress("JAVA_CLASS_ON_COMPANION")
|
||||
private val log = LoggerFactory.getLogger(javaClass.enclosingClass)
|
||||
|
||||
var charset: Charset = if (getOsName().contains("Windows")) Charset.forName("Windows-1252") else Charset.defaultCharset()
|
||||
var charset: Charset = Charset.defaultCharset()
|
||||
init {
|
||||
log.info("os.name: " + getOsName())
|
||||
log.info("user.home: " + System.getProperty("user.home"))
|
||||
|
|
|
@ -129,7 +129,7 @@ fun provisionRemote(args: Array<String>) {
|
|||
val pwFromSecret = Password(pwSecret.plain())
|
||||
|
||||
val config = readWorkplaceConfigFromFile() ?: WorkplaceConfig()
|
||||
Prov.newInstance(RemoteProcessor(host, userName, pwFromSecret), OS.LINUX.name).provisionWorkplace(
|
||||
Prov.newInstance(RemoteProcessor(host, userName, pwFromSecret)).provisionWorkplace(
|
||||
config.type,
|
||||
config.ssh?.keyPair(),
|
||||
config.gpg?.keyPair(),
|
||||
|
|
|
@ -7,8 +7,6 @@ import org.domaindrivenarchitecture.provs.test.testLocal
|
|||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
|
||||
|
@ -25,8 +23,7 @@ internal class ProvTest {
|
|||
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun cmd_onLinux() {
|
||||
fun cmd() {
|
||||
// when
|
||||
val res = Prov.newInstance(name = "testing").cmd("echo --testing--").success
|
||||
|
||||
|
@ -35,9 +32,8 @@ internal class ProvTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@ContainerTest
|
||||
fun sh_onLinux() {
|
||||
fun sh() {
|
||||
// given
|
||||
val script = """
|
||||
# test some script commands
|
||||
|
@ -55,10 +51,9 @@ internal class ProvTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@ContainerTest
|
||||
@NonCi
|
||||
fun sh_onLinux_with_dir_and_sudo() {
|
||||
fun sh_with_dir_and_sudo() {
|
||||
// given
|
||||
val script = """
|
||||
# test some script commands
|
||||
|
@ -76,36 +71,6 @@ internal class ProvTest {
|
|||
assert(res)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
fun cmd_onWindows() {
|
||||
// when
|
||||
val res = Prov.newInstance(name = "testing").cmd("echo --testing--").success
|
||||
|
||||
// then
|
||||
assert(res)
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
fun sh_onWindows() {
|
||||
// given
|
||||
val script = """
|
||||
# test some script commands
|
||||
|
||||
ping -n 1 nu.nl
|
||||
echo something
|
||||
ping -n 1 github.com
|
||||
"""
|
||||
|
||||
// when
|
||||
val res = Prov.newInstance(name = "testing").sh(script).success
|
||||
|
||||
// then
|
||||
assert(res)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun def_modeOptional_result_true() {
|
||||
// given
|
||||
|
@ -332,17 +297,7 @@ internal class ProvTest {
|
|||
|
||||
println(outContent.toString())
|
||||
|
||||
val expectedOutput = if (OS.WINDOWS.isCurrentOs) "\n" +
|
||||
"============================================== SUMMARY (test Instance) ============================================== \n" +
|
||||
"> Success -- methodThatProvidesSomeOutput (requireLast) \n" +
|
||||
"---> FAILED -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" +
|
||||
"---> Success -- sh \n" +
|
||||
"------> Success -- cmd [cmd.exe, /c, echo -Start test-]\n" +
|
||||
"------> Success -- cmd [cmd.exe, /c, echo Some output]\n" +
|
||||
"---> Success -- sh \n" +
|
||||
"------> Success -- cmd [cmd.exe, /c, echo -End test-]\n" +
|
||||
"============================================ SUMMARY END ============================================ \n"
|
||||
else if (OS.LINUX.isCurrentOs()) {
|
||||
val expectedOutput =
|
||||
"============================================== SUMMARY (test instance) ============================================== \n" +
|
||||
"> \u001B[92mSuccess\u001B[0m -- methodThatProvidesSomeOutput (requireLast) \n" +
|
||||
"---> \u001B[91mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" +
|
||||
|
@ -355,9 +310,6 @@ internal class ProvTest {
|
|||
"Overall > \u001B[92mSuccess\u001B[0m\n" +
|
||||
"============================================ SUMMARY END ============================================ \n" +
|
||||
"\n"
|
||||
} else {
|
||||
"OS " + System.getProperty("os.name") + " not yet supported"
|
||||
}
|
||||
|
||||
assertEquals(expectedOutput, outContent.toString().replace("\r", ""))
|
||||
}
|
||||
|
@ -428,7 +380,6 @@ internal class ProvTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@NonCi
|
||||
fun inContainer_locally() {
|
||||
// given
|
||||
|
@ -454,7 +405,6 @@ internal class ProvTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@Disabled // run manually after updating host and remoteUser
|
||||
fun inContainer_remotely() {
|
||||
// given
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.junit.jupiter.api.condition.OS
|
|||
internal class UbuntuHostDockerKtTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@NonCi
|
||||
fun runAndCheckAndExitContainer() {
|
||||
// when
|
||||
|
|
|
@ -7,15 +7,12 @@ import org.domaindrivenarchitecture.provs.core.docker.dockerProvideImage
|
|||
import org.domaindrivenarchitecture.provs.core.docker.dockerimages.DockerImage
|
||||
import org.domaindrivenarchitecture.provs.core.processors.ContainerStartMode
|
||||
import org.domaindrivenarchitecture.provs.core.processors.ContainerUbuntuHostProcessor
|
||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainerName
|
||||
import org.domaindrivenarchitecture.provs.test.tags.NonCi
|
||||
import org.domaindrivenarchitecture.provs.test.testDockerWithSudo
|
||||
import org.domaindrivenarchitecture.provs.test.testLocal
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
||||
internal class UbuntuProvTests {
|
||||
|
||||
|
@ -28,7 +25,6 @@ internal class UbuntuProvTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun that_ping_works() {
|
||||
// when
|
||||
val res = testLocal().outerPing()
|
||||
|
@ -38,7 +34,6 @@ internal class UbuntuProvTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun that_cmd_works() {
|
||||
// given
|
||||
val a = testLocal()
|
||||
|
@ -55,7 +50,6 @@ internal class UbuntuProvTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
@NonCi
|
||||
fun that_cmd_works_with_sudo() {
|
||||
// given
|
||||
|
@ -70,7 +64,6 @@ internal class UbuntuProvTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun that_nested_shells_work() {
|
||||
// given
|
||||
val a = testLocal()
|
||||
|
@ -87,7 +80,6 @@ internal class UbuntuProvTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun that_xec_works() {
|
||||
// given
|
||||
val a = testLocal()
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package org.domaindrivenarchitecture.provs.core.platformTest
|
||||
|
||||
import org.domaindrivenarchitecture.provs.core.Prov
|
||||
import org.domaindrivenarchitecture.provs.test.testLocal
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
||||
internal class WinProvTests {
|
||||
|
||||
private fun Prov.ping(url: String) = def {
|
||||
cmd("ping $url")
|
||||
}
|
||||
|
||||
private fun Prov.outerPing() = def { ping("nu.nl") }
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
fun def_definesPing_function() {
|
||||
// when
|
||||
val res = testLocal().outerPing()
|
||||
|
||||
// then
|
||||
assert(res.success)
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
fun cmd_executesCommand() {
|
||||
// given
|
||||
val a = testLocal()
|
||||
|
||||
// when
|
||||
val res1 = a.cmd("echo %cd%")
|
||||
val dir = res1.out?.trim()
|
||||
val res2 = a.cmd("echo abc", dir)
|
||||
|
||||
// then
|
||||
assert(res1.success)
|
||||
assert(res1.success)
|
||||
assertEquals( "abc", res2.out?.trim())
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test
|
|||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
internal class ContainerProcessorTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -5,15 +5,12 @@ import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
|||
import org.domaindrivenarchitecture.provs.test.testDockerWithSudo
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS.LINUX
|
||||
|
||||
val DEFAULT_START_MODE_TEST_CONTAINER = ContainerStartMode.USE_RUNNING_ELSE_CREATE
|
||||
|
||||
class ContainerUbuntuHostProcessorTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(LINUX)
|
||||
@ContainerTest
|
||||
fun test_execution() {
|
||||
// given
|
||||
|
|
|
@ -7,15 +7,12 @@ import org.domaindrivenarchitecture.provs.core.escapeSingleQuoteForShell
|
|||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
|
||||
|
||||
internal class LocalProcessorTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun cmd_with_printf_on_Linux() {
|
||||
fun cmd_with_printf() {
|
||||
// given
|
||||
val prov = Prov.newInstance()
|
||||
val text = "abc123!§\\\$%%&/\"\\äöü'"
|
||||
|
@ -30,8 +27,7 @@ internal class LocalProcessorTest {
|
|||
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun cmd_with_nested_shell_and_printf_on_Linux() {
|
||||
fun cmd_with_nested_shell_and_printf() {
|
||||
// given
|
||||
val prov = Prov.newInstance()
|
||||
val text = "abc123!§\\$%%&/\"\\äöü'"
|
||||
|
@ -46,29 +42,11 @@ internal class LocalProcessorTest {
|
|||
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
fun cmd_with_echo_on_Windows() {
|
||||
// given
|
||||
val prov = Prov.newInstance()
|
||||
val text = "abc123!\"#"
|
||||
|
||||
// when
|
||||
val res = prov.cmd("echo $text")
|
||||
|
||||
// then
|
||||
assert(res.success)
|
||||
assertEquals( text + "\r\n", res.out)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun cmdNoLog_linux() {
|
||||
fun cmdNoLog() {
|
||||
// given
|
||||
val prov = Prov.newInstance()
|
||||
val text = "abc123!#"
|
||||
val osSpecificText = if (OS.WINDOWS.isCurrentOs) text else "'$text'"
|
||||
|
||||
val osSpecificText = "'$text'"
|
||||
|
||||
// when
|
||||
val res = prov.cmdNoLog("echo $osSpecificText")
|
||||
|
|
|
@ -31,7 +31,8 @@ internal class ProvisionFirewallKtTest {
|
|||
dockerImage.imageName(),
|
||||
ContainerStartMode.USE_RUNNING_ELSE_CREATE, // already started in previous statement
|
||||
ContainerEndMode.EXIT_AND_REMOVE
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
// when
|
||||
val res = a.requireAll {
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.junit.jupiter.api.condition.OS
|
|||
internal class ProvisionKeysTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun provisionKeysCurrentUser() {
|
||||
// given
|
||||
val a = defaultTestContainer()
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.junit.jupiter.api.condition.OS
|
|||
internal class ProvisionUserKtTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.LINUX)
|
||||
fun configureUser() {
|
||||
// given
|
||||
val a = defaultTestContainer()
|
||||
|
|
Loading…
Reference in a new issue