From 92525f544457940279619a1253a60376e2701938 Mon Sep 17 00:00:00 2001 From: az Date: Fri, 8 Apr 2022 12:51:28 +0200 Subject: [PATCH] add tests for syspec FileSpec --- .../infrastructure/VerificationKtTest.kt | 72 ++++++++++++++++--- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/VerificationKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/VerificationKtTest.kt index c924b7b..679eed0 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/VerificationKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/syspec/infrastructure/VerificationKtTest.kt @@ -1,17 +1,15 @@ package org.domaindrivenarchitecture.provs.syspec.infrastructure 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.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.SocketSpec import org.domaindrivenarchitecture.provs.syspec.domain.SyspecConfig import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.tags.ContainerTest 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.assertTrue import org.junit.jupiter.api.Test @@ -23,16 +21,21 @@ internal class VerificationKtTest { // given val dir = "/home/testuser/testdir" val prov = defaultTestContainer() - prov.createDirs(dir) + prov.createDirs(dir) // when - val res = defaultTestContainer().task { + val res = prov.task { verify(FolderSpec(dir)) ProvResult(true) // dummy } + val res2 = prov.task { + verify(FolderSpec(dir, exists = false)) + ProvResult(true) // dummy + } // then assertTrue(res.success) + assertFalse(res2.success) } @ContainerTest @@ -42,13 +45,61 @@ internal class VerificationKtTest { val prov = defaultTestContainer() // when - val res = defaultTestContainer().task { + val res = prov.task { verify(FolderSpec(dir)) ProvResult(true) // dummy } + val res2 = prov.task { + verify(FolderSpec(dir, exists = false)) + ProvResult(true) // dummy + } // then 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 @@ -59,9 +110,12 @@ internal class VerificationKtTest { @Test fun test_verify_socketSpec_successfully() { // given - val out: List = ("Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process \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") + val out: List = + ("Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process \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 val res = testLocal().task {