diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-08-25 01:28:08 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-08-25 01:28:08 +0200 |
| commit | 157853ea0839fac4e066c012c21a4900aaf4c30f (patch) | |
| tree | 716215093c68c27e606670a58ad1c9cd56d26341 /libs/samba/src/test/java | |
| parent | 5b0bd926c6c8a1d3f65acd170b56c582abcee488 (diff) | |
samba: Add support for live list
Using polling (every 10s) as libsmb2 has no watch/event support.
(Unsure if SMB protocol has any support).
Diffstat (limited to 'libs/samba/src/test/java')
| -rw-r--r-- | libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt b/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt index d2a2e04..b0ecf03 100644 --- a/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt +++ b/libs/samba/src/test/java/org/the_jk/cleversync/samba/SambaTreeTest.kt @@ -11,10 +11,15 @@ import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config +import org.robolectric.shadows.ShadowLooper +import org.the_jk.cleversync.io.Directory import org.the_jk.cleversync.io.samba.SambaCredentials +import org.the_jk.cleversync.safeValue import java.io.File import java.nio.charset.StandardCharsets import java.nio.file.Files +import java.util.concurrent.TimeUnit +import kotlin.time.Duration.Companion.seconds @Config(manifest=Config.NONE) @RunWith(RobolectricTestRunner::class) @@ -54,6 +59,16 @@ class SambaTreeTest { } @Test + fun listEmptyRootLive() { + SambaTreeFactory.tree(uri, credentials).getOrThrow().use { root -> + val content = root.liveList().safeValue() + assertThat(content?.directories).isEmpty() + assertThat(content?.files).isEmpty() + assertThat(content?.links).isEmpty() + } + } + + @Test fun listRootWithSymlink() { File(shareDir, "dir").mkdir() File(shareDir, "file").writeText("foo") @@ -148,6 +163,42 @@ class SambaTreeTest { assertThat(File(shareDir, "file").readText()).isEqualTo("foobar") } + @Test + fun createDirectory() { + SambaTreeFactory.modifiableTree(uri, credentials).getOrThrow().use { root -> + val foo = root.createDirectory("foo") + assertThat(foo.name).isEqualTo("foo") + val fooContent = foo.list() + assertThat(fooContent.directories).isEmpty() + assertThat(fooContent.files).isEmpty() + assertThat(fooContent.links).isEmpty() + val content = root.list() + assertThat(content.directories).contains(foo) + assertThat(content.files).isEmpty() + assertThat(content.links).isEmpty() + } + + assertThat(File(shareDir, "foo").isDirectory).isTrue() + } + + @Test(timeout = 10000) + fun observeCreateDirectory() { + SambaTreeFactory.modifiableTree(uri, credentials).getOrThrow().use { root -> + val content = root.liveList() + var dir: Directory? = null + content.observeForever { + if (it.directories.size == 1) dir = it.directories[0] + } + root.createDirectory("foo") + while (dir == null) { + ShadowLooper.idleMainLooper(10, TimeUnit.SECONDS) + } + assertThat(dir?.name).isEqualTo("foo") + } + + assertThat(File(shareDir, "foo").isDirectory).isTrue() + } + companion object { private lateinit var uri: String private lateinit var credentials: SambaCredentials |
