FsServerTest.kt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2019-2022 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. @file:Suppress("DEPRECATION", "DEPRECATION_ERROR")
  10. package net.mamoe.mirai.mock.test
  11. import kotlinx.coroutines.runBlocking
  12. import net.mamoe.mirai.mock.resserver.TmpResourceServer
  13. import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
  14. import net.mamoe.mirai.utils.mkParentDirs
  15. import org.junit.jupiter.api.Test
  16. import kotlin.io.path.writeText
  17. import kotlin.test.assertEquals
  18. @Suppress("RemoveExplicitTypeArguments")
  19. internal class FsServerTest {
  20. @Test
  21. fun testFsServer() = runBlocking<Unit> {
  22. val fsServer = TmpResourceServer.newInMemoryTmpResourceServer()
  23. fsServer.startupServer()
  24. val testFile = "Test".toByteArray().toExternalResource()
  25. val resourceId = fsServer.uploadResource(testFile)
  26. val response = fsServer.resolveHttpUrl(resourceId).toURL().readText()
  27. assertEquals("Test", response)
  28. val pt0 = fsServer.storageRoot.resolve("/rand/etc/randrand/somedata")
  29. pt0.mkParentDirs()
  30. pt0.writeText("Test")
  31. assertEquals("Test", fsServer.resolveHttpUrlByPath(pt0).toURL().readText())
  32. fsServer.close()
  33. }
  34. }