refactor: finished server refactoring
This commit is contained in:
parent
b06b9ab8a2
commit
af8ab62604
7 changed files with 13 additions and 15 deletions
|
@ -6,7 +6,7 @@ import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provisions a k3s server, either locally or on a remote machine depending on the given arguments.
|
* Provisions a server, either locally or on a remote machine depending on the given arguments.
|
||||||
* Depending on the cli parameter "type" it will install the k3s server as standalone or as a container.
|
* Depending on the cli parameter "type" it will install the k3s server as standalone or as a container.
|
||||||
*
|
*
|
||||||
* Get help with option -h
|
* Get help with option -h
|
||||||
|
@ -21,7 +21,7 @@ fun main(args: Array<String>) {
|
||||||
val prov = createProvInstance(cmd.target)
|
val prov = createProvInstance(cmd.target)
|
||||||
|
|
||||||
when (cmd.type()) {
|
when (cmd.type()) {
|
||||||
CliK3sArgumentsParser.K3sType.K3S -> prov.provisionK3s()
|
CliServerArgumentsParser.K3sType.K3S -> prov.provisionK3s()
|
||||||
CliK3sArgumentsParser.K3sType.K3D -> prov.installK3sAsContainers()
|
CliServerArgumentsParser.K3sType.K3D -> prov.installK3sAsContainers()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@ import kotlinx.cli.ArgType
|
||||||
import kotlinx.cli.default
|
import kotlinx.cli.default
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.cli.CliTargetParser
|
import org.domaindrivenarchitecture.provs.framework.core.cli.CliTargetParser
|
||||||
|
|
||||||
class CliK3sArgumentsParser(name: String) : CliTargetParser(name) {
|
class CliServerArgumentsParser(name: String) : CliTargetParser(name) {
|
||||||
|
|
||||||
enum class K3sType {
|
enum class K3sType {
|
||||||
K3S, K3D
|
K3S, K3D
|
|
@ -8,16 +8,16 @@ class ServerCliCommand(private val k3sType: String, val target: TargetCliCommand
|
||||||
return target.isValid() && hasValidK3sType()
|
return target.isValid() && hasValidK3sType()
|
||||||
}
|
}
|
||||||
private fun hasValidK3sType(): Boolean {
|
private fun hasValidK3sType(): Boolean {
|
||||||
return CliK3sArgumentsParser.K3sType.values().map { it.name }.contains(k3sType.uppercase())
|
return CliServerArgumentsParser.K3sType.values().map { it.name }.contains(k3sType.uppercase())
|
||||||
}
|
}
|
||||||
fun type() = CliK3sArgumentsParser.K3sType.valueOf(k3sType.uppercase())
|
fun type() = CliServerArgumentsParser.K3sType.valueOf(k3sType.uppercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parseServerArguments(
|
fun parseServerArguments(
|
||||||
programName: String = "java -jar provs.jar",
|
programName: String = "java -jar provs.jar",
|
||||||
args: Array<String>
|
args: Array<String>
|
||||||
): ServerCliCommand {
|
): ServerCliCommand {
|
||||||
val parser = CliK3sArgumentsParser(programName)
|
val parser = CliServerArgumentsParser(programName)
|
||||||
parser.parse(args)
|
parser.parse(args)
|
||||||
|
|
||||||
return ServerCliCommand(
|
return ServerCliCommand(
|
|
@ -1,11 +1,9 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.application
|
package org.domaindrivenarchitecture.provs.server.application
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.server.application.CliK3sArgumentsParser
|
|
||||||
import org.domaindrivenarchitecture.provs.server.application.parseServerArguments
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import org.junit.jupiter.api.Assertions.*
|
||||||
|
|
||||||
internal class CliK3sCommandKtTest {
|
internal class CliServerCommandKtTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_parseServerArguments_are_valid_for_k3s() {
|
fun test_parseServerArguments_are_valid_for_k3s() {
|
||||||
|
@ -14,7 +12,7 @@ internal class CliK3sCommandKtTest {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(cmd.isValid())
|
assertTrue(cmd.isValid())
|
||||||
assertEquals(CliK3sArgumentsParser.K3sType.K3S, cmd.type())
|
assertEquals(CliServerArgumentsParser.K3sType.K3S, cmd.type())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -24,7 +22,7 @@ internal class CliK3sCommandKtTest {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertFalse(cmd.isValid())
|
assertFalse(cmd.isValid())
|
||||||
assertEquals(CliK3sArgumentsParser.K3sType.K3S, cmd.type())
|
assertEquals(CliServerArgumentsParser.K3sType.K3S, cmd.type())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -34,7 +32,7 @@ internal class CliK3sCommandKtTest {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(cmd.isValid())
|
assertTrue(cmd.isValid())
|
||||||
assertEquals(CliK3sArgumentsParser.K3sType.K3S, cmd.type())
|
assertEquals(CliServerArgumentsParser.K3sType.K3S, cmd.type())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -44,6 +42,6 @@ internal class CliK3sCommandKtTest {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(cmd.isValid())
|
assertTrue(cmd.isValid())
|
||||||
assertEquals(CliK3sArgumentsParser.K3sType.K3D, cmd.type())
|
assertEquals(CliServerArgumentsParser.K3sType.K3D, cmd.type())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@ import org.domaindrivenarchitecture.provs.server.application.main
|
||||||
import org.junit.jupiter.api.Disabled
|
import org.junit.jupiter.api.Disabled
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
internal class CliKtTest {
|
internal class CliServerKtTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled // run manually -- todo mock execution
|
@Disabled // run manually -- todo mock execution
|
Loading…
Reference in a new issue