Test of rename folder

This commit is contained in:
Karlatemp 2021-12-19 00:46:46 +08:00
parent 84b66692e9
commit 1d1a77ff1a
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
3 changed files with 90 additions and 1 deletions

View File

@ -11,6 +11,7 @@ package net.mamoe.console.integrationtest
import net.mamoe.console.integrationtest.testpoints.DoNothingPoint
import net.mamoe.console.integrationtest.testpoints.MCITBSelfAssertions
import net.mamoe.console.integrationtest.testpoints.plugin.PluginDataRenameToIdTest
import org.junit.jupiter.api.Test
import java.io.File
import java.lang.management.ManagementFactory
@ -32,6 +33,7 @@ class MiraiConsoleIntegrationTestBootstrap {
launcher.points = listOf<Any>(
DoNothingPoint,
MCITBSelfAssertions,
PluginDataRenameToIdTest,
).asSequence().map { v ->
when (v) {
is Class<*> -> v

View File

@ -0,0 +1,82 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.console.integrationtest.testpoints.plugin
import net.mamoe.console.integrationtest.AbstractTestPointAsPlugin
import net.mamoe.console.integrationtest.assertNotExists
import net.mamoe.mirai.console.data.AutoSavePluginConfig
import net.mamoe.mirai.console.data.AutoSavePluginData
import net.mamoe.mirai.console.data.value
import net.mamoe.mirai.console.extension.PluginComponentStorage
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.utils.touch
import java.io.File
import kotlin.test.assertEquals
internal object PluginDataRenameToIdTest : AbstractTestPointAsPlugin() {
object TestData : AutoSavePluginData("testdata") {
public val test: String by value("")
}
object TestConf : AutoSavePluginConfig("testconf") {
public val test: String by value("")
}
override fun newPluginDescription(): JvmPluginDescription {
return JvmPluginDescription(
id = "net.mamoe.testpoint.plugin-data-rename-to-id-test",
version = "1.0.0",
name = "PluginDataRenameToIdTest",
)
}
override fun beforeConsoleStartup() {
File("config/PluginDataRenameToIdTest/test.txt").touch()
File("config/PluginDataRenameToIdTest/testconf.yml").writeText(
"""
test: a
""".trimIndent()
)
File("data/PluginDataRenameToIdTest/test.txt").touch()
File("data/PluginDataRenameToIdTest/testdata.yml").writeText(
"""
test: a
""".trimIndent()
)
}
override fun KotlinPlugin.onLoad0(storage: PluginComponentStorage) {
File("config/PluginDataRenameToIdTest").assertNotExists()
File("data/PluginDataRenameToIdTest").assertNotExists()
}
override fun KotlinPlugin.onEnable0() {
TestData.reload()
TestConf.reload()
TestData.save()
TestConf.save()
assertEquals("a", TestConf.test)
assertEquals("a", TestData.test)
}
override fun onConsoleStartSuccessfully() {
File("config/PluginDataRenameToIdTest/test.txt").assertNotExists()
File("data/PluginDataRenameToIdTest/test.txt").assertNotExists()
File("config/PluginDataRenameToIdTest/testconf.yml").assertNotExists()
File("data/PluginDataRenameToIdTest/testdata.yml").assertNotExists()
}
}

View File

@ -151,4 +151,9 @@ public fun File.resolveCreateFile(relative: String): File = this.resolve(relativ
public fun File.resolveCreateFile(relative: File): File = this.resolve(relative).apply { createFileIfNotExists() }
public fun File.resolveMkdir(relative: String): File = this.resolve(relative).apply { mkdirs() }
public fun File.resolveMkdir(relative: File): File = this.resolve(relative).apply { mkdirs() }
public fun File.resolveMkdir(relative: File): File = this.resolve(relative).apply { mkdirs() }
public fun File.touch(): File = apply {
parentFile?.mkdirs()
createNewFile()
}