v0.8.8 - add ip-address validation, rename method check due to naming conflict with Kotlin's check

This commit is contained in:
az 2021-04-16 13:45:05 +02:00
parent 2623eb857f
commit 5baedbb32e
7 changed files with 66 additions and 44 deletions

View file

@ -6,23 +6,18 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
apply plugin: 'idea'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply plugin: 'maven-publish'
apply plugin: 'java-test-fixtures'
apply plugin: 'maven-publish'
group = 'io.provs'
version = '0.8.8-SNAPSHOT'
version = '0.8.8'
repositories {
mavenCentral()
jcenter()
}
test {
@ -53,10 +48,9 @@ java {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0" // JVM dependency
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation group: 'com.hierynomus', name: 'sshj', version: '0.30.0'
implementation group: 'com.hierynomus', name: 'sshj', version: '0.31.0'
api "org.slf4j:slf4j-api:1.7.30"
api "ch.qos.logback:logback-classic:1.2.3"
@ -79,6 +73,7 @@ task fatJar(type: Jar) {
with jar
}
//create a single Jar with all dependencies excl. Kotlin libs without version-number but with suffix "latest"
task fatJarLatest(type: Jar) {
doFirst {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
@ -114,7 +109,6 @@ task uberJar(type: Jar) {
archiveClassifier = 'uber'
}
//create a single Jar with all dependencies incl. Kotlin libs - as ...-latest
task uberJarLatest(type: Jar) {
@ -162,6 +156,8 @@ publishing {
header(HttpHeaderAuthentication)
}
}
} else {
mavenLocal()
}
}
}

View file

@ -148,9 +148,9 @@ open class Prov protected constructor(private val processor: Processor, val name
/**
* Executes command cmd and returns true in case of success else false.
* The success resp. failure does not count into the overall success.
* The success resp. failure is not evaluated, i.e. it is not taken into account for the overall success.
*/
fun check(cmd: String, dir: String? = null): Boolean {
fun chk(cmd: String, dir: String? = null): Boolean {
return cmdNoEval(cmd, dir).success
}

View file

@ -5,6 +5,7 @@ import io.provs.processors.ContainerStartMode
import io.provs.processors.ContainerUbuntuHostProcessor
import io.provs.processors.RemoteProcessor
import java.io.File
import java.net.InetAddress
/**
* Returns the name of the calling function but excluding some functions of the prov framework
@ -71,7 +72,10 @@ fun local(): Prov {
*/
@Suppress("unused") // used by other libraries resp. KotlinScript
fun remote(host: String, remoteUser: String, password: Secret? = null, platform: String? = null): Prov {
return Prov.newInstance(RemoteProcessor(host, remoteUser, password), platform)
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)
}

View file

@ -13,10 +13,11 @@ import java.io.BufferedReader
import java.io.File
import java.io.IOException
import java.io.InputStreamReader
import java.net.InetAddress
import java.util.concurrent.TimeUnit
class RemoteProcessor(ip: String, user: String, password: Secret? = null) : Processor {
class RemoteProcessor(ip: InetAddress, user: String, password: Secret? = null) : Processor {
companion object {
@Suppress("JAVA_CLASS_ON_COMPANION")

View file

@ -344,7 +344,7 @@ internal class ProvTest {
@Test
fun check_returnsTrue() {
// when
val res = local().check("echo 123")
val res = local().chk("echo 123")
// then
assertTrue(res)
@ -353,7 +353,7 @@ internal class ProvTest {
@Test
fun check_returnsFalse() {
// when
val res = local().check("cmddoesnotexist")
val res = local().chk("cmddoesnotexist")
// then
assertFalse(res)

View file

@ -0,0 +1,49 @@
package io.provs
import io.provs.test.defaultTestContainer
import io.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import java.net.UnknownHostException
internal class UtilsKtTest {
@Test
fun test_getCallingMethodName() {
// when
val s = getCallingMethodName()
// then
assertEquals("test_getCallingMethodName", s)
}
@Test
@ContainerTest
fun runCmdInContainer() {
// when
val res = defaultTestContainer().cmd("echo something")
// then
assertTrue(res.success)
}
@Test
fun remote_emptyHost() {
assertThrows(IllegalArgumentException::class.java,
{ remote("", "user") })
}
@Test
fun remote_invalidHost() {
assertThrows(
UnknownHostException::class.java,
{ remote("invalid_host", "user") })
}
@Test
@Disabled // run manually after having updated user
fun test_remote() {
assertTrue(remote("127.0.0.1", "user").cmd("echo sth").success)
}
}

View file

@ -1,28 +0,0 @@
package io.provs
import io.provs.test.defaultTestContainer
import io.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
internal class UtilsTest {
@Test
fun test_getCallingMethodName() {
// when
val s = getCallingMethodName()
// then
Assertions.assertEquals("test_getCallingMethodName", s)
}
@Test
@ContainerTest
fun test_docker() {
// when
val res = defaultTestContainer().cmd("echo something")
// then
Assertions.assertEquals(true, res.success)
}
}