summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2021-08-16 15:45:27 +0200
committernea <romangraef@gmail.com>2021-08-16 15:45:27 +0200
commit1159d5ad67594d98f0aa4e9899ece0406f423497 (patch)
tree03eea5b84aaa45cb876e3ce8251f98e0c61e62ac
parent3e1becfa688f2cba280c475caf39aec3ce14a095 (diff)
downloadwebos-1159d5ad67594d98f0aa4e9899ece0406f423497.tar.gz
webos-1159d5ad67594d98f0aa4e9899ece0406f423497.tar.bz2
webos-1159d5ad67594d98f0aa4e9899ece0406f423497.zip
file service tests
-rw-r--r--build.gradle.kts8
-rw-r--r--src/jsMain/kotlin/io/files.kt2
-rw-r--r--src/jsTest/kotlin/io/FileServiceTest.kt42
3 files changed, 50 insertions, 2 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 1302fab..99c6139 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,6 +1,7 @@
plugins {
kotlin("multiplatform") version "1.5.21"
id("io.kotest.multiplatform") version "5.0.0.3"
+ id("com.bnorm.power.kotlin-power-assert") version "0.10.0"
}
repositories {
@@ -10,6 +11,10 @@ repositories {
val kotestVersion: String by project
+configure<com.bnorm.power.PowerAssertGradleExtension> {
+ functions = listOf("kotlin.assert", "kotlin.test.assertTrue", "kotlin.test.assertFalse", "kotlin.test.assertEquals")
+}
+
kotlin {
targets {
js(IR) {
@@ -18,7 +23,8 @@ kotlin {
webpackTask {
output.libraryTarget = "umd"
}
- testTask { useMocha() } }
+ testTask { useMocha() }
+ }
}
}
sourceSets {
diff --git a/src/jsMain/kotlin/io/files.kt b/src/jsMain/kotlin/io/files.kt
index 9e3e6a0..4c53c4e 100644
--- a/src/jsMain/kotlin/io/files.kt
+++ b/src/jsMain/kotlin/io/files.kt
@@ -175,7 +175,7 @@ class PrimitiveFileService : FileService<PrimitiveINode> {
if (storageBlobs.containsKey(iNode.internalPath)) return CreateFileResult.Failure.AlreadyExists
val parent = getStorageBlob(resolve(iNode, ".."))
if (parent !is PrimitiveStorageBlob.Directory) return CreateFileResult.Failure.NoParent
- if (hasPermission(user, parent) { write }) return CreateFileResult.Failure.NoPermission
+ if (!hasPermission(user, parent) { write }) return CreateFileResult.Failure.NoPermission
return null
}
diff --git a/src/jsTest/kotlin/io/FileServiceTest.kt b/src/jsTest/kotlin/io/FileServiceTest.kt
new file mode 100644
index 0000000..2ad5ee3
--- /dev/null
+++ b/src/jsTest/kotlin/io/FileServiceTest.kt
@@ -0,0 +1,42 @@
+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 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))
+ }
+ 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))
+ }
+
+}