mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
feat: support tencent cos
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
package app.termora
|
||||
|
||||
import app.termora.database.DataEntity
|
||||
import app.termora.database.DataType
|
||||
import app.termora.database.OwnerType
|
||||
import app.termora.database.SettingEntity
|
||||
import org.jetbrains.exposed.v1.jdbc.Database
|
||||
import org.jetbrains.exposed.v1.jdbc.SchemaUtils
|
||||
import org.jetbrains.exposed.v1.jdbc.insert
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import kotlin.test.Test
|
||||
|
||||
|
||||
class ExposedTest {
|
||||
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val database = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver", user = "sa")
|
||||
|
||||
transaction(database) {
|
||||
SchemaUtils.create(DataEntity, SettingEntity)
|
||||
|
||||
println(DataEntity.insert {
|
||||
it[ownerId] = "Test"
|
||||
it[ownerType] = OwnerType.User.name
|
||||
it[type] = DataType.KeywordHighlight.name
|
||||
it[data] = "hello 中文".repeat(10000)
|
||||
} get DataEntity.id)
|
||||
|
||||
println(SettingEntity.insert {
|
||||
it[name] = "Test"
|
||||
it[value] = "hello 中文".repeat(10000)
|
||||
} get SettingEntity.id)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class HostTest {
|
||||
"""
|
||||
{
|
||||
"name": "test",
|
||||
"protocol": SSHProtocolProvider.PROTOCOL,
|
||||
"protocol": "SSH",
|
||||
"test": ""
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package app.termora.account
|
||||
|
||||
import kotlin.test.Test
|
||||
|
||||
class ServerManagerTest {
|
||||
@Test
|
||||
fun test() {
|
||||
ServerManager.getInstance().login(
|
||||
Server(
|
||||
name = "test",
|
||||
server = "http://127.0.0.1:8080"
|
||||
), "admin", "admin"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
package app.termora.vfs2.sftp
|
||||
|
||||
import app.termora.SSHDTest
|
||||
import app.termora.randomUUID
|
||||
import org.apache.commons.vfs2.*
|
||||
import org.apache.commons.vfs2.impl.DefaultFileSystemManager
|
||||
import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider
|
||||
import org.apache.sshd.sftp.client.SftpClientFactory
|
||||
import java.io.File
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class MySftpFileProviderTest : SSHDTest() {
|
||||
|
||||
companion object {
|
||||
init {
|
||||
val fileSystemManager = DefaultFileSystemManager()
|
||||
fileSystemManager.addProvider("sftp", MySftpFileProvider.instance)
|
||||
fileSystemManager.addProvider("file", DefaultLocalFileProvider())
|
||||
fileSystemManager.init()
|
||||
VFS.setManager(fileSystemManager)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSetExecutable() {
|
||||
val file = newFileObject("/config/test.txt")
|
||||
file.createFile()
|
||||
file.refresh()
|
||||
assertFalse(file.isExecutable)
|
||||
file.setExecutable(true, false)
|
||||
file.refresh()
|
||||
assertTrue(file.isExecutable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateFile() {
|
||||
val file = newFileObject("/config/test.txt")
|
||||
assertFalse(file.exists())
|
||||
file.createFile()
|
||||
assertTrue(file.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWriteAndReadFile() {
|
||||
val file = newFileObject("/config/test.txt")
|
||||
file.createFile()
|
||||
assertFalse(file.content.isOpen)
|
||||
|
||||
val os = file.content.outputStream
|
||||
os.write("test".toByteArray())
|
||||
os.flush()
|
||||
assertTrue(file.content.isOpen)
|
||||
|
||||
os.close()
|
||||
assertFalse(file.content.isOpen)
|
||||
|
||||
val input = file.content.inputStream
|
||||
assertEquals("test", String(input.readAllBytes()))
|
||||
assertTrue(file.content.isOpen)
|
||||
input.close()
|
||||
assertFalse(file.content.isOpen)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCreateFolder() {
|
||||
val file = newFileObject("/config/test")
|
||||
assertFalse(file.exists())
|
||||
file.createFolder()
|
||||
assertTrue(file.exists())
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testSftpClient() {
|
||||
val session = newClientSession()
|
||||
val client = SftpClientFactory.instance().createSftpClient(session)
|
||||
assertTrue(client.isOpen)
|
||||
session.close()
|
||||
assertFalse(client.isOpen)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCopy() {
|
||||
val file = newFileObject("/config/sshd.pid")
|
||||
val filepath = File("build", randomUUID())
|
||||
val localFile = getVFS().resolveFile("file://${filepath.absolutePath}")
|
||||
|
||||
localFile.copyFrom(file, Selectors.SELECT_ALL)
|
||||
assertEquals(
|
||||
file.content.getString(Charsets.UTF_8),
|
||||
localFile.content.getString(Charsets.UTF_8)
|
||||
)
|
||||
|
||||
localFile.delete()
|
||||
}
|
||||
|
||||
private fun getVFS(): FileSystemManager {
|
||||
return VFS.getManager()
|
||||
}
|
||||
|
||||
private fun newFileObject(path: String): FileObject {
|
||||
val vfs = getVFS()
|
||||
val fileSystemOptions = FileSystemOptions()
|
||||
MySftpFileSystemConfigBuilder.getInstance()
|
||||
.setSftpFileSystem(fileSystemOptions, SftpClientFactory.instance().createSftpFileSystem(newClientSession()))
|
||||
return vfs.resolveFile("sftp://${path}", fileSystemOptions)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user