ImageUploadTest.kt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. package net.mamoe.mirai.mock.test
  10. import kotlinx.coroutines.runBlocking
  11. import net.mamoe.mirai.message.data.Image
  12. import net.mamoe.mirai.message.data.Image.Key.queryUrl
  13. import net.mamoe.mirai.mock.MockBotFactory
  14. import net.mamoe.mirai.mock.utils.randomImageContent
  15. import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
  16. import org.junit.jupiter.api.AfterEach
  17. import org.junit.jupiter.api.Test
  18. import org.junit.jupiter.api.TestInstance
  19. import java.net.URL
  20. import kotlin.test.assertTrue
  21. @TestInstance(TestInstance.Lifecycle.PER_METHOD)
  22. internal class ImageUploadTest {
  23. internal val bot = MockBotFactory.newMockBotBuilder()
  24. .id(1234567890)
  25. .nick("Sakura")
  26. .create()
  27. @AfterEach
  28. internal fun botDestroy() {
  29. bot.close()
  30. }
  31. @Test
  32. fun testImageUpload() = runBlocking<Unit> {
  33. val data = Image.randomImageContent()
  34. val img = bot.asFriend.uploadImage(
  35. data.toExternalResource().toAutoCloseable()
  36. )
  37. println(img.imageId)
  38. assertTrue {
  39. data.contentEquals(URL(img.queryUrl()).readBytes())
  40. }
  41. }
  42. }