simplify class KnownHost and add test
This commit is contained in:
parent
203a94fab2
commit
a5a1e95639
3 changed files with 27 additions and 15 deletions
|
@ -25,24 +25,11 @@ open class KnownHost protected constructor(val hostName: String, val hostKeys: L
|
|||
)
|
||||
|
||||
@JvmStatic
|
||||
protected val values = listOf(KnownHost.GITHUB, KnownHost.GITLAB)
|
||||
protected val values = listOf(GITHUB, GITLAB)
|
||||
|
||||
fun values(): List<KnownHost> {
|
||||
return values
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun valueOf(value: String): KnownHost = valueOf(value, KnownHost.values)
|
||||
|
||||
@JvmStatic
|
||||
protected fun valueOf(value: String, valueList: List<KnownHost>): KnownHost {
|
||||
for (type in valueList) {
|
||||
if (value.uppercase().equals(type.hostName)) {
|
||||
return type
|
||||
}
|
||||
}
|
||||
throw RuntimeException("No KnownHost found for value: $value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov
|
|||
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.addKnownHost
|
||||
|
||||
|
||||
fun Prov.addKnownHosts(knownHosts: List<KnownHost> = defaultKnownHosts) = task {
|
||||
fun Prov.addKnownHosts(knownHosts: List<KnownHost> = KnownHost.values()) = task {
|
||||
for (knownHost in knownHosts) {
|
||||
with(knownHost) {
|
||||
addKnownHost(hostName, hostKeys, verifyKeys = true)
|
||||
|
|
|
@ -5,7 +5,9 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta
|
|||
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.base.KNOWN_HOSTS_FILE
|
||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
||||
class KnownHostTest {
|
||||
|
@ -25,5 +27,28 @@ class KnownHostTest {
|
|||
// then
|
||||
assertTrue(res.success)
|
||||
}
|
||||
|
||||
|
||||
// Subclass of KnownHost for test knownHostSubclass_includes_additional_host
|
||||
class KnownHostsSubclass(hostName: String, hostKeys: List<HostKey>): KnownHost(hostName, hostKeys) {
|
||||
|
||||
companion object {
|
||||
val ANOTHER_HOST = KnownHostsSubclass("anotherhost.com", listOf("key1"))
|
||||
|
||||
fun values(): List<KnownHost> {
|
||||
return values + ANOTHER_HOST
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun knownHostSubclass_includes_additional_host() {
|
||||
// when
|
||||
val hosts = KnownHostsSubclass.values()
|
||||
|
||||
// then
|
||||
assertTrue(hosts.size > 1)
|
||||
assertEquals("key1", hosts.last().hostKeys[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue