style: テストのスタイルを修正

This commit is contained in:
usbharu 2023-04-30 01:38:59 +09:00
parent fcabce7380
commit 028c988475
10 changed files with 69 additions and 65 deletions

View File

@ -3,5 +3,4 @@ package dev.usbharu.hideout
import io.ktor.server.application.*
fun Application.empty() {
}

View File

@ -15,7 +15,6 @@ import java.time.Instant
class ActivityPubKtTest {
@Test
fun HttpSignTest(): Unit = runBlocking {
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
override suspend fun save(user: User): User {
TODO("Not yet implemented")
@ -96,12 +95,13 @@ class ActivityPubKtTest {
override suspend fun nextId(): Long {
TODO("Not yet implemented")
}
})
val httpClient = HttpClient(MockEngine { httpRequestData ->
respondOk()
}) {
val httpClient = HttpClient(
MockEngine { httpRequestData ->
respondOk()
}
) {
install(httpSignaturePlugin) {
keyMap = ktorKeyMap
}
@ -112,7 +112,5 @@ class ActivityPubKtTest {
}
httpClient.postAp("https://localhost", "test", JsonLd(emptyList()))
}
}

View File

@ -46,7 +46,6 @@ class KtorKeyMapTest {
generateKeyPair.private.toPem(),
createdAt = Instant.now()
)
}
override suspend fun findByDomain(domain: String): List<User> {
@ -92,7 +91,6 @@ class KtorKeyMapTest {
override suspend fun nextId(): Long {
TODO("Not yet implemented")
}
})
ktorKeyMap.getPrivateKey("test")

View File

@ -18,7 +18,6 @@ import java.time.Clock
import java.time.Instant
import java.time.ZoneId
class UserRepositoryTest {
lateinit var db: Database
@ -35,7 +34,6 @@ class UserRepositoryTest {
@AfterEach
fun tearDown() {
transaction(db) {
SchemaUtils.drop(UsersFollowers)
SchemaUtils.drop(Users)
}
@ -43,11 +41,14 @@ class UserRepositoryTest {
@Test
fun `findFollowersById フォロワー一覧を取得`() = runTest {
val userRepository = UserRepository(db, object : IdGenerateService {
override suspend fun generateId(): Long {
TODO("Not yet implemented")
val userRepository = UserRepository(
db,
object : IdGenerateService {
override suspend fun generateId(): Long {
TODO("Not yet implemented")
}
}
})
)
val user = userRepository.save(
User(
id = 0L,
@ -98,16 +99,18 @@ class UserRepositoryTest {
userRepository.findFollowersById(user.id).let {
assertIterableEquals(listOf(follower, follower2), it)
}
}
@Test
fun `createFollower フォロワー追加`() = runTest {
val userRepository = UserRepository(db, object : IdGenerateService {
override suspend fun generateId(): Long {
TODO("Not yet implemented")
val userRepository = UserRepository(
db,
object : IdGenerateService {
override suspend fun generateId(): Long {
TODO("Not yet implemented")
}
}
})
)
val user = userRepository.save(
User(
0L,
@ -140,11 +143,9 @@ class UserRepositoryTest {
)
userRepository.createFollower(user.id, follower.id)
transaction {
val followerIds =
UsersFollowers.select { UsersFollowers.userId eq user.id }.map { it[UsersFollowers.followerId] }
assertIterableEquals(listOf(follower.id), followerIds)
}
}
}

View File

@ -32,7 +32,6 @@ import java.time.Instant
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class UsersAPTest {
@Test()
@ -100,8 +99,8 @@ class UsersAPTest {
}
}
// @Disabled
@Test()
// @Disabled
fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication {
environment {
config = ApplicationConfig("empty.conf")
@ -167,16 +166,21 @@ class UsersAPTest {
}
}
// @Disabled
@Test
// @Disabled
fun contentType_Test() {
assertTrue(ContentType.Application.Activity.match("application/activity+json"))
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
assertTrue(listOf.find { contentType ->
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
}.let { it != null })
assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""))
assertTrue(
listOf.find { contentType ->
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
}.let { it != null }
)
assertTrue(
ContentType.Application.JsonLd.match(
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
)
)
}
@Test

View File

@ -1,6 +1,6 @@
package dev.usbharu.hideout.service
//import kotlinx.coroutines.NonCancellable.message
// import kotlinx.coroutines.NonCancellable.message
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
@ -16,17 +16,13 @@ class TwitterSnowflakeIdGenerateServiceTest {
val mutex = Mutex()
val mutableListOf = mutableListOf<Long>()
coroutineScope {
repeat(500000) {
launch(Dispatchers.IO) {
val id = TwitterSnowflakeIdGenerateService.generateId()
mutex.withLock {
mutableListOf.add(id)
}
}
}
}

View File

@ -122,28 +122,30 @@ class ActivityPubFollowServiceImplTest {
mock(),
activityPubUserService,
userService,
HttpClient(MockEngine { httpRequestData ->
assertEquals(person.inbox, httpRequestData.url.toString())
val accept = Accept(
type = emptyList(),
name = "Follow",
`object` = Follow(
HttpClient(
MockEngine { httpRequestData ->
assertEquals(person.inbox, httpRequestData.url.toString())
val accept = Accept(
type = emptyList(),
name = "Follow",
`object` = "https://example.com",
actor = "https://follower.example.com"
),
actor = "https://example.com"
)
accept.context += "https://www.w3.org/ns/activitystreams"
assertEquals(
accept,
Config.configData.objectMapper.readValue<Accept>(
httpRequestData.body.toByteArray().decodeToString()
`object` = Follow(
type = emptyList(),
name = "Follow",
`object` = "https://example.com",
actor = "https://follower.example.com"
),
actor = "https://example.com"
)
)
respondOk()
})
accept.context += "https://www.w3.org/ns/activitystreams"
assertEquals(
accept,
Config.configData.objectMapper.readValue<Accept>(
httpRequestData.body.toByteArray().decodeToString()
)
)
respondOk()
}
)
)
activityPubFollowService.receiveFollowJob(
JobProps(

View File

@ -73,7 +73,13 @@ class ActivityPubNoteServiceImplTest {
val jobQueueParentService = mock<JobQueueParentService>()
val activityPubNoteService = ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService)
val postEntity = PostEntity(
1L, 1L, null, "test text", 1L, 1, "https://example.com"
1L,
1L,
null,
"test text",
1L,
1,
"https://example.com"
)
activityPubNoteService.createNote(postEntity)
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
@ -82,17 +88,19 @@ class ActivityPubNoteServiceImplTest {
@Test
fun `createPostJob 新しい投稿のJob`() = runTest {
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
val httpClient = HttpClient(MockEngine { httpRequestData ->
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
respondOk()
})
val httpClient = HttpClient(
MockEngine { httpRequestData ->
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
respondOk()
}
)
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock())
activityPubNoteService.createNoteJob(
JobProps(
data = mapOf<String, Any>(
DeliverPostJob.actor.name to "https://follower.example.com",
DeliverPostJob.post.name to "{\"id\":1,\"userId\":1,\"inReplyToId\":null,\"text\":\"test text\"," +
"\"createdAt\":1,\"updatedAt\":1,\"url\":\"https://example.com\"}",
"\"createdAt\":1,\"updatedAt\":1,\"url\":\"https://example.com\"}",
DeliverPostJob.inbox.name to "https://follower.example.com/inbox"
),
json = Json

View File

@ -50,10 +50,8 @@ class UserServiceTest {
@Test
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
Config.configData = ConfigData(domain = "example.com", url = "https://example.com")
val userRepository = mock<IUserRepository> {
onBlocking { nextId() } doReturn 113345L
}

View File

@ -4,7 +4,6 @@ import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.DatabaseConfig
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(DBResetInterceptor::class)
abstract class DatabaseTestBase {
companion object {
@ -12,7 +11,8 @@ abstract class DatabaseTestBase {
Database.connect(
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
driver = "org.h2.Driver",
databaseConfig = DatabaseConfig { useNestedTransactions = true })
databaseConfig = DatabaseConfig { useNestedTransactions = true }
)
}
}
}