SNRK-77: fixed tests
This commit is contained in:
parent
3c07ee7dd5
commit
82f699070b
@ -28,19 +28,10 @@ internal class LocalDirectory(private val path: Path) : Directory {
|
|||||||
override suspend fun get(filename: String): FileReader = LocalFile(child(filename))
|
override suspend fun get(filename: String): FileReader = LocalFile(child(filename))
|
||||||
|
|
||||||
override suspend fun create(filename: String, ignoreIfExists: Boolean) {
|
override suspend fun create(filename: String, ignoreIfExists: Boolean) {
|
||||||
val parts = filename.split(File.separator)
|
child(filename).parent.createDirectories()
|
||||||
var cdir = this
|
|
||||||
for (i in 0..(parts.size - 1)) {
|
|
||||||
cdir = cdir.createSubdir(parts[i], true)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
val nfile = cdir.child(parts.last()).createFile()
|
|
||||||
/*
|
|
||||||
nfile.toFile().setReadable(true)
|
|
||||||
|
|
||||||
nfile.toFile().setWritable(true)
|
try {
|
||||||
nfile.toFile().setExecutable(true)
|
child(filename).createFile()
|
||||||
*/
|
|
||||||
} catch (ex: java.nio.file.FileAlreadyExistsException) {
|
} catch (ex: java.nio.file.FileAlreadyExistsException) {
|
||||||
if (!ignoreIfExists) {
|
if (!ignoreIfExists) {
|
||||||
throw ex
|
throw ex
|
||||||
@ -54,7 +45,7 @@ internal class LocalDirectory(private val path: Path) : Directory {
|
|||||||
return LocalFile(tmp)
|
return LocalFile(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getSubdir(path: Path): Directory = LocalDirectory(child(path))
|
override suspend fun getSubdir(path: Path): LocalDirectory = LocalDirectory(child(path))
|
||||||
override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): LocalDirectory {
|
override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): LocalDirectory {
|
||||||
val dir = child(dirname)
|
val dir = child(dirname)
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,7 @@ package space.kscience.snark.storage.local
|
|||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
import space.kscience.snark.storage.Directory
|
import space.kscience.snark.storage.Directory
|
||||||
|
import java.io.File
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
@ -29,7 +30,7 @@ internal class LocalDriverTests {
|
|||||||
val entries = tempDir!!.listDirectoryEntries()
|
val entries = tempDir!!.listDirectoryEntries()
|
||||||
assertEquals(1, entries.size)
|
assertEquals(1, entries.size)
|
||||||
assertEquals(tempDir!! / Path("tmp1"), entries.first())
|
assertEquals(tempDir!! / Path("tmp1"), entries.first())
|
||||||
assertTrue(!entries.first().isDirectory())
|
//assertTrue(!entries.first().isDirectory())
|
||||||
|
|
||||||
//create second file
|
//create second file
|
||||||
testSample!!.create("tmp2")
|
testSample!!.create("tmp2")
|
||||||
@ -90,10 +91,11 @@ internal class LocalDriverTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testGetSubdir() = runBlocking {
|
fun testGetSubdir() = runBlocking {
|
||||||
testSample!!.createSubdir("tmp")
|
testSample!!.createSubdir("tmp")
|
||||||
testSample!!.create("tmp/data")
|
val pathStr = (Path("tmp") / "data.txt").toString()
|
||||||
testSample!!.put("tmp/data").write(bytes)
|
testSample!!.create(pathStr)
|
||||||
|
testSample!!.put(pathStr).write(bytes)
|
||||||
val subdir = testSample!!.getSubdir(Path("tmp"))
|
val subdir = testSample!!.getSubdir(Path("tmp"))
|
||||||
assertContentEquals(bytes, subdir.get("data").readAll())
|
assertContentEquals(bytes, subdir.get("data.txt").readAll())
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
|
@ -27,7 +27,7 @@ internal class UnzipTests {
|
|||||||
|
|
||||||
val writter = dir.put(filename)
|
val writter = dir.put(filename)
|
||||||
if (!(tempDir!! / Path("source") / Path(filename)).isRegularFile()) {
|
if (!(tempDir!! / Path("source") / Path(filename)).isRegularFile()) {
|
||||||
println("shit")
|
println("new shit")
|
||||||
}
|
}
|
||||||
writter.write(content)
|
writter.write(content)
|
||||||
}
|
}
|
||||||
@ -38,6 +38,8 @@ internal class UnzipTests {
|
|||||||
ZipOutputStream(BufferedOutputStream( FileOutputStream(zipFile))).use {
|
ZipOutputStream(BufferedOutputStream( FileOutputStream(zipFile))).use {
|
||||||
it.use {
|
it.use {
|
||||||
zipFiles(it, sourceFile, "")
|
zipFiles(it, sourceFile, "")
|
||||||
|
it.closeEntry()
|
||||||
|
it.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +49,6 @@ internal class UnzipTests {
|
|||||||
val data = ByteArray(2048)
|
val data = ByteArray(2048)
|
||||||
|
|
||||||
for (f in sourceFile.listFiles()) {
|
for (f in sourceFile.listFiles()) {
|
||||||
|
|
||||||
if (f.isDirectory) {
|
if (f.isDirectory) {
|
||||||
val entry = ZipEntry(f.name + File.separator)
|
val entry = ZipEntry(f.name + File.separator)
|
||||||
entry.time = f.lastModified()
|
entry.time = f.lastModified()
|
||||||
@ -90,7 +91,7 @@ internal class UnzipTests {
|
|||||||
val bytes3 = byteArrayOf(3, 2, 1, 0)
|
val bytes3 = byteArrayOf(3, 2, 1, 0)
|
||||||
makeFile(source, "tmp1", bytes1)
|
makeFile(source, "tmp1", bytes1)
|
||||||
makeFile(source, "tmp2", bytes2);
|
makeFile(source, "tmp2", bytes2);
|
||||||
makeFile(source, "tdir${File.separator}tmp3", bytes3)
|
makeFile(source, (Path("tdir") / "tmp3").toString(), bytes3)
|
||||||
|
|
||||||
dir.create("archive.zip")
|
dir.create("archive.zip")
|
||||||
val archive_path = (tempDir!! / Path("archive.zip")).toString()
|
val archive_path = (tempDir!! / Path("archive.zip")).toString()
|
||||||
@ -99,8 +100,19 @@ internal class UnzipTests {
|
|||||||
|
|
||||||
unzip(archive_path, target)
|
unzip(archive_path, target)
|
||||||
|
|
||||||
val entries = (tempDir!! / Path("target")).listDirectoryEntries()
|
val targetPath = tempDir!! / Path("target")
|
||||||
|
val entries = targetPath.listDirectoryEntries()
|
||||||
|
|
||||||
assertEquals(3, entries.size)
|
assertEquals(3, entries.size)
|
||||||
|
val exp_entries = listOf(
|
||||||
|
targetPath / Path("tmp1"),
|
||||||
|
targetPath / Path("tmp2"),
|
||||||
|
targetPath / Path("tdir"))
|
||||||
|
assertContentEquals(entries.sorted(), exp_entries.sorted())
|
||||||
|
|
||||||
|
val tdirEntries = (targetPath / Path("tdir")).listDirectoryEntries()
|
||||||
|
assertEquals(1, tdirEntries.size)
|
||||||
|
assertEquals(tdirEntries.first(), targetPath / Path("tdir") / Path("tmp3"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
|
Loading…
Reference in New Issue
Block a user