summaryrefslogtreecommitdiff
path: root/src/jsTest
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2021-08-20 15:33:32 +0200
committernea <romangraef@gmail.com>2021-08-20 15:33:58 +0200
commit5042498c8fe12751c1b6560ae1fde07e7cd78259 (patch)
tree688aa93978ffffd0b15c639768fdad6f17609bdd /src/jsTest
parent65a6ffeb6761994d4d69011c87f23fe074f7a1f7 (diff)
downloadwebos-master.tar.gz
webos-master.tar.bz2
webos-master.zip
aaaaaaaaHEADmaster
Diffstat (limited to 'src/jsTest')
-rw-r--r--src/jsTest/kotlin/ProjectConfig.kt3
-rw-r--r--src/jsTest/kotlin/io/FileServiceTest.kt59
-rw-r--r--src/jsTest/kotlin/io/PathTest.kt104
3 files changed, 0 insertions, 166 deletions
diff --git a/src/jsTest/kotlin/ProjectConfig.kt b/src/jsTest/kotlin/ProjectConfig.kt
deleted file mode 100644
index faa4d69..0000000
--- a/src/jsTest/kotlin/ProjectConfig.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-import io.kotest.core.config.AbstractProjectConfig
-
-class ProjectConfig : AbstractProjectConfig()
diff --git a/src/jsTest/kotlin/io/FileServiceTest.kt b/src/jsTest/kotlin/io/FileServiceTest.kt
deleted file mode 100644
index 9c9c8b9..0000000
--- a/src/jsTest/kotlin/io/FileServiceTest.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package io
-
-import User
-import io.kotest.core.spec.style.FunSpec
-import kotlin.test.assertEquals
-import kotlin.test.assertFalse
-import kotlin.test.assertTrue
-
-class FileServiceTest : FunSpec({
- generateTests("Primitive", ::PrimitiveFileService)
-})
-
-fun <INode> FunSpec.generateTests(name: String, provider: () -> FileService<INode>) {
- val aPath = Path.of("/a") as Path.Absolute
- val bPath = Path.of("/a/b") as Path.Absolute
- val homePath = Path.of("/roothome") as Path.Absolute
- val dataA = "a".encodeToByteArray()
- val rootUser = User("root", homePath, true)
- test("$name: root inode exists") {
- val fileService = provider()
- val rootInode = fileService.getINode(Path.root)
- assertTrue(fileService.exists(rootInode))
- assertEquals(fileService.getPath(rootInode), Path.root)
- }
- test("$name: CRUD a file") {
- val fileService = provider()
- val aInode = fileService.getINode(aPath)
- assertFalse(fileService.exists(aInode))
- assertEquals(CreateFileResult.Created, CreateFileResult.Created)
- assertEquals(fileService.createFile(aInode, rootUser), CreateFileResult.Created)
- assertTrue(fileService.exists(aInode))
- assertTrue(fileService.isFile(aInode))
- assertFalse(fileService.isSymlink(aInode))
- assertFalse(fileService.isDirectory(aInode))
- assertEquals(fileService.readFromFile(aInode, rootUser), ReadFileResult.Read(ByteArray(0)))
- assertEquals(fileService.writeToFile(aInode, rootUser, dataA), WriteFileResult.Written)
- assertEquals(fileService.readFromFile(aInode, rootUser), ReadFileResult.Read(dataA))
- assertTrue(fileService.isFile(aInode))
- assertEquals(fileService.deleteFile(aInode, rootUser), DeleteFileResult.Deleted)
- assertFalse(fileService.isFile(aInode))
- assertFalse(fileService.exists(aInode))
- }
- test("$name: CRUD a directory structure") {
- val fileService = provider()
- val aINode = fileService.getINode(aPath)
- val bINode = fileService.getINode(bPath)
- assertFalse(fileService.exists(aINode))
- assertFalse(fileService.exists(bINode))
- assertEquals(fileService.createDirectory(aINode, rootUser), CreateFileResult.Created)
- assertEquals(fileService.createFile(bINode, rootUser), CreateFileResult.Created)
- assertTrue(fileService.exists(aINode))
- assertTrue(fileService.exists(bINode))
- assertEquals(fileService.writeToFile(bINode, rootUser, dataA), WriteFileResult.Written)
- assertEquals(fileService.readFromFile(bINode, rootUser), ReadFileResult.Read(dataA))
- assertEquals(fileService.deleteFile(aINode, rootUser), DeleteFileResult.Deleted)
- assertFalse(fileService.exists(bINode))
- assertFalse(fileService.exists(aINode))
- }
-}
diff --git a/src/jsTest/kotlin/io/PathTest.kt b/src/jsTest/kotlin/io/PathTest.kt
deleted file mode 100644
index 9ba8a9e..0000000
--- a/src/jsTest/kotlin/io/PathTest.kt
+++ /dev/null
@@ -1,104 +0,0 @@
-package io
-
-import io.kotest.assertions.assertSoftly
-import io.kotest.core.spec.style.FunSpec
-import io.kotest.data.forAll
-import io.kotest.data.row
-import io.kotest.matchers.be
-import io.kotest.matchers.should
-import io.kotest.matchers.shouldBe
-import io.kotest.matchers.types.beOfType
-import io.kotest.matchers.types.shouldBeTypeOf
-
-class PathTest : FunSpec({
- val homeDir = Path.of("/home") as Path.Absolute
- test("recognize relative paths as such") {
- forAll(
- row(Path.of("a/b")),
- row(Path.of(".")),
- row(Path.of("a", "b")),
- row(Path.ofShell("a/b", userHome = homeDir)),
- row(Path.ofShell(".", userHome = homeDir)),
- row(Path.ofShell("a", "b", userHome = homeDir)),
- row(Path.ofShell(listOf("a", "b"), userHome = homeDir)),
- ) {
- assertSoftly(it) { shouldBeTypeOf<Path.Relative>() }
- }
- }
- test("recognize absolute paths as such") {
- forAll(
- row(Path.of("/a/b")),
- row(Path.of("/")),
- row(Path.ofShell("/b/c", userHome = homeDir)),
- ) {
- assertSoftly(it) { shouldBeTypeOf<Path.Absolute>() }
- }
- }
- test("Path.of(x).stringPath == x") {
- forAll(
- row("/"),
- row("/a/b"),
- row("a/b"),
- row("."),
- ) { name ->
- assertSoftly(Path.of(name).stringPath) {
- shouldBe(name)
- }
- assertSoftly(Path.ofShell(name, homeDir).stringPath) {
- shouldBe(name)
- }
- }
- }
- test("Shell resolution of home directory") {
- forAll(
- row("~/a", "/home/a"),
- row("~", "/home"),
- row("~/.", "/home/."),
- row("/a", "/a"),
- row("a", "a"),
- ) { a, b ->
- assertSoftly(Path.ofShell(a, homeDir).stringPath) {
- shouldBe(b)
- }
- }
- }
- test("Relative path resolution works") {
- forAll(
- row("/a/b", "c/d", "/a/b/c/d"),
- row("/a/b", "/c/d", "/c/d"),
- row("/a/", "c", "/a/c"),
- ) { a, b, c ->
- val x = Path.of(a)
- val y = Path.of(b)
- val z = x.resolve(y)
- assertSoftly {
- x should beOfType<Path.Absolute>()
- z should beOfType<Path.Absolute>()
- z.stringPath should be(c)
- }
- }
- }
- test("Equality checks should work") {
- forAll(
- row("a"),
- row("a/b"),
- row("/a/b"),
- row("c//d")
- ) {
- assertSoftly {
- Path.of(it) should be(Path.of(it))
- }
- }
- }
- test("relaitivization works") {
- forAll(
- row("/a/b", "/a", ".."),
- row("/a", "/a/b", "b"),
- row("/a/b", "/a/c", "../c"),
- ) { a, b, c ->
- assertSoftly {
- Path.of(a).shouldBeTypeOf<Path.Absolute>().relativize(Path.of(b)) shouldBe Path.of(c)
- }
- }
- }
-})