Yokan / rebuild
Course 1 8624561

IosLocalFileServiceTest.kt

composeApp/src/iosTest/kotlin/eu/friedcutlet/yokan/services/files/IosLocalFileServiceTest.kt

test / fixture80 lines
1package eu.friedcutlet.yokan.services.files23import kotlin.test.Test4import kotlin.test.assertContentEquals5import kotlin.test.assertEquals6import kotlin.test.assertFalse7import kotlin.test.assertTrue8import platform.Foundation.NSURL910class IosLocalFileServiceTest {11    @Test12    fun writesEmptyFilesWithoutDereferencingMissingStorage() {13        val files = createPlatformLocalFileService()14        val path = "${files.cacheRoot}/tests/empty-${kotlin.random.Random.nextLong()}.bin"1516        try {17            files.writeBytes(path, ByteArray(0))1819            assertTrue(files.exists(path))20            assertContentEquals(ByteArray(0), files.readBytes(path))21        } finally {22            files.deleteRecursively(path)23        }24    }2526    @Test27    fun boundedReadOfSmallFileDoesNotAllocateTheLargeAllowance() {28        val files = createPlatformLocalFileService()29        val path = "${files.cacheRoot}/tests/bounded-${kotlin.random.Random.nextLong()}.bin"30        val bytes = byteArrayOf(1, 2, 3, 4)31        try {32            files.writeBytes(path, bytes)33            assertContentEquals(bytes, files.readBytesBounded(path, 512L * 1024 * 1024))34        } finally {35            files.deleteRecursively(path)36        }37    }3839    @Test40    fun persistedFolderBookmarkKeepsLogicalPathsForLaterReads() {41        val files = createPlatformLocalFileService()42        val root = "${files.cacheRoot}/bookmark-${kotlin.random.Random.nextLong()}"43        val content = byteArrayOf(4, 5, 6)44        files.writeBytes("$root/book.cbz", content)4546        try {47            assertEquals(root, IosSecurityScopedBookmarks.persist(NSURL.fileURLWithPath(root)))48            assertTrue(files.exists(root))49            assertEquals("$root/book.cbz", files.listLocalEntries(root)?.single()?.path)50            assertContentEquals(content, files.readBytes("$root/book.cbz"))51        } finally {52            files.deleteRecursively(root)53        }54    }5556    @Test57    fun publishesStagedDirectoryAndRefusesExistingDestination() {58        val files = createPlatformLocalFileService()59        val root = "${files.cacheRoot}/publish-${kotlin.random.Random.nextLong()}"60        val staged = "$root/staged"61        val destination = "$root/job"62        val existingStage = "$root/staged-existing"63        val existingDestination = "$root/job-existing"64        files.writeBytes("$staged/page", byteArrayOf(1, 2, 3))65        files.writeBytes("$existingStage/page", byteArrayOf(4, 5, 6))66        files.writeBytes("$existingDestination/keep", byteArrayOf(7))6768        try {69            assertTrue(files.publishDirectoryIfAbsent(staged, destination))70            assertFalse(files.exists(staged))71            assertContentEquals(byteArrayOf(1, 2, 3), files.readBytes("$destination/page"))7273            assertFalse(files.publishDirectoryIfAbsent(existingStage, existingDestination))74            assertTrue(files.exists("$existingStage/page"))75            assertContentEquals(byteArrayOf(7), files.readBytes("$existingDestination/keep"))76        } finally {77            files.deleteRecursively(root)78        }79    }80}81

Search chapters, reference and source filenames.