From 93685e94409df0c91dcf387ec0a3e6e650f74226 Mon Sep 17 00:00:00 2001 From: LamGC Date: Tue, 12 Jul 2022 01:29:19 +0800 Subject: [PATCH] =?UTF-8?q?test(config):=20=E4=BC=98=E5=8C=96=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 AppPaths 的单元测试也覆盖了, 直接方便了. --- scalabot-app/src/test/kotlin/AppConfigTest.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scalabot-app/src/test/kotlin/AppConfigTest.kt b/scalabot-app/src/test/kotlin/AppConfigTest.kt index cc96ad1..fb664d6 100644 --- a/scalabot-app/src/test/kotlin/AppConfigTest.kt +++ b/scalabot-app/src/test/kotlin/AppConfigTest.kt @@ -16,6 +16,7 @@ import java.io.IOException import java.net.URL import java.nio.file.Files import java.nio.file.Path +import kotlin.io.path.deleteExisting import kotlin.test.* internal class AppPathsTest { @@ -319,6 +320,7 @@ internal class AppPathsTest { } val fullInitializeDir = Files.createTempDirectory(testDir, "fullInitialize") + fullInitializeDir.deleteExisting() System.setProperty(AppPaths.PathConst.PROP_DATA_PATH, fullInitializeDir.toString()) assertEquals(fullInitializeDir.toString(), AppPaths.DATA_ROOT.path, "测试路径设定失败.") @@ -376,9 +378,20 @@ internal class AppPathsTest { if (path.file.isFile) { assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}") } - path.reset() } + AppPaths.CONFIG_APPLICATION.file.writeText("Test-APPLICATION") + AppPaths.CONFIG_BOT.file.writeText("Test-BOT") + assertFalse(initialFiles(), "方法试图在部分配置已初始化的情况下提醒用户编辑初始配置文件.") + assertEquals( + "Test-APPLICATION", AppPaths.CONFIG_APPLICATION.file.readText(), + "config.json 被覆盖. initialized 并未阻止重复初始化." + ) + assertEquals( + "Test-BOT", AppPaths.CONFIG_BOT.file.readText(), + "bot.json 被覆盖. initialized 并未阻止重复初始化." + ) + System.getProperties().remove(AppPaths.PathConst.PROP_DATA_PATH) }