From 1159d5ad67594d98f0aa4e9899ece0406f423497 Mon Sep 17 00:00:00 2001 From: nea Date: Mon, 16 Aug 2021 15:45:27 +0200 Subject: file service tests --- src/jsTest/kotlin/io/FileServiceTest.kt | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/jsTest/kotlin/io/FileServiceTest.kt (limited to 'src/jsTest/kotlin/io') 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 FunSpec.generateTests(name: String, provider: () -> FileService) { + 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)) + } + +} -- cgit