add tests for syspec FileSpec
This commit is contained in:
parent
ecbcac81f8
commit
92525f5444
1 changed files with 63 additions and 9 deletions
|
@ -1,17 +1,15 @@
|
||||||
package org.domaindrivenarchitecture.provs.syspec.infrastructure
|
package org.domaindrivenarchitecture.provs.syspec.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDir
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContainsText
|
import org.domaindrivenarchitecture.provs.syspec.domain.FileSpec
|
||||||
import org.domaindrivenarchitecture.provs.syspec.domain.FolderSpec
|
import org.domaindrivenarchitecture.provs.syspec.domain.FolderSpec
|
||||||
import org.domaindrivenarchitecture.provs.syspec.domain.SocketSpec
|
import org.domaindrivenarchitecture.provs.syspec.domain.SocketSpec
|
||||||
import org.domaindrivenarchitecture.provs.syspec.domain.SyspecConfig
|
import org.domaindrivenarchitecture.provs.syspec.domain.SyspecConfig
|
||||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||||
import org.domaindrivenarchitecture.provs.test.testLocal
|
import org.domaindrivenarchitecture.provs.test.testLocal
|
||||||
import org.junit.jupiter.api.Assertions
|
|
||||||
import org.junit.jupiter.api.Assertions.assertFalse
|
import org.junit.jupiter.api.Assertions.assertFalse
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -23,16 +21,21 @@ internal class VerificationKtTest {
|
||||||
// given
|
// given
|
||||||
val dir = "/home/testuser/testdir"
|
val dir = "/home/testuser/testdir"
|
||||||
val prov = defaultTestContainer()
|
val prov = defaultTestContainer()
|
||||||
prov.createDirs(dir)
|
prov.createDirs(dir)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val res = defaultTestContainer().task {
|
val res = prov.task {
|
||||||
verify(FolderSpec(dir))
|
verify(FolderSpec(dir))
|
||||||
ProvResult(true) // dummy
|
ProvResult(true) // dummy
|
||||||
}
|
}
|
||||||
|
val res2 = prov.task {
|
||||||
|
verify(FolderSpec(dir, exists = false))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(res.success)
|
assertTrue(res.success)
|
||||||
|
assertFalse(res2.success)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ContainerTest
|
@ContainerTest
|
||||||
|
@ -42,13 +45,61 @@ internal class VerificationKtTest {
|
||||||
val prov = defaultTestContainer()
|
val prov = defaultTestContainer()
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val res = defaultTestContainer().task {
|
val res = prov.task {
|
||||||
verify(FolderSpec(dir))
|
verify(FolderSpec(dir))
|
||||||
ProvResult(true) // dummy
|
ProvResult(true) // dummy
|
||||||
}
|
}
|
||||||
|
val res2 = prov.task {
|
||||||
|
verify(FolderSpec(dir, exists = false))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertFalse(res.success)
|
assertFalse(res.success)
|
||||||
|
assertTrue(res2.success)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ContainerTest
|
||||||
|
fun test_verify_file_existing() {
|
||||||
|
// given
|
||||||
|
val file = "/home/testuser/testfile"
|
||||||
|
val prov = defaultTestContainer()
|
||||||
|
prov.createFile(file,"testcontent")
|
||||||
|
|
||||||
|
// when
|
||||||
|
val res = prov.task {
|
||||||
|
verify(FileSpec(file))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
val res2 = prov.task {
|
||||||
|
verify(FileSpec(file, exists = false))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(res.success)
|
||||||
|
assertFalse(res2.success)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ContainerTest
|
||||||
|
fun test_verify_file_nonexisting() {
|
||||||
|
// given
|
||||||
|
val file = "/home/testuser/testfile-nonexisting"
|
||||||
|
val prov = defaultTestContainer()
|
||||||
|
|
||||||
|
// when
|
||||||
|
val res = prov.task {
|
||||||
|
verify(FileSpec(file))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
val res2 = prov.task {
|
||||||
|
verify(FileSpec(file, exists = false))
|
||||||
|
ProvResult(true) // dummy
|
||||||
|
}
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertFalse(res.success)
|
||||||
|
assertTrue(res2.success)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,9 +110,12 @@ internal class VerificationKtTest {
|
||||||
@Test
|
@Test
|
||||||
fun test_verify_socketSpec_successfully() {
|
fun test_verify_socketSpec_successfully() {
|
||||||
// given
|
// given
|
||||||
val out: List<String> = ("Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process \n" +
|
val out: List<String> =
|
||||||
"udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:* users:((\"avahi-daemon\",pid=906,fd=12)) uid:116 ino:25024 sk:3 <-> \n" +
|
("Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process \n" +
|
||||||
"tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((\"sshd\",pid=1018,fd=3)) ino:29320 sk:a <-> \n").split("\n")
|
"udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:* users:((\"avahi-daemon\",pid=906,fd=12)) uid:116 ino:25024 sk:3 <-> \n" +
|
||||||
|
"tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((\"sshd\",pid=1018,fd=3)) ino:29320 sk:a <-> \n").split(
|
||||||
|
"\n"
|
||||||
|
)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val res = testLocal().task {
|
val res = testLocal().task {
|
||||||
|
|
Loading…
Reference in a new issue