mirror of https://github.com/usbharu/Hideout.git
style: テストのスタイルを修正
This commit is contained in:
parent
fcabce7380
commit
028c988475
|
@ -3,5 +3,4 @@ package dev.usbharu.hideout
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
|
|
||||||
fun Application.empty() {
|
fun Application.empty() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.time.Instant
|
||||||
class ActivityPubKtTest {
|
class ActivityPubKtTest {
|
||||||
@Test
|
@Test
|
||||||
fun HttpSignTest(): Unit = runBlocking {
|
fun HttpSignTest(): Unit = runBlocking {
|
||||||
|
|
||||||
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
val ktorKeyMap = KtorKeyMap(object : IUserRepository {
|
||||||
override suspend fun save(user: User): User {
|
override suspend fun save(user: User): User {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
|
@ -96,12 +95,13 @@ class ActivityPubKtTest {
|
||||||
override suspend fun nextId(): Long {
|
override suspend fun nextId(): Long {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
val httpClient = HttpClient(MockEngine { httpRequestData ->
|
val httpClient = HttpClient(
|
||||||
respondOk()
|
MockEngine { httpRequestData ->
|
||||||
}) {
|
respondOk()
|
||||||
|
}
|
||||||
|
) {
|
||||||
install(httpSignaturePlugin) {
|
install(httpSignaturePlugin) {
|
||||||
keyMap = ktorKeyMap
|
keyMap = ktorKeyMap
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,5 @@ class ActivityPubKtTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient.postAp("https://localhost", "test", JsonLd(emptyList()))
|
httpClient.postAp("https://localhost", "test", JsonLd(emptyList()))
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ class KtorKeyMapTest {
|
||||||
generateKeyPair.private.toPem(),
|
generateKeyPair.private.toPem(),
|
||||||
createdAt = Instant.now()
|
createdAt = Instant.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByDomain(domain: String): List<User> {
|
override suspend fun findByDomain(domain: String): List<User> {
|
||||||
|
@ -92,7 +91,6 @@ class KtorKeyMapTest {
|
||||||
override suspend fun nextId(): Long {
|
override suspend fun nextId(): Long {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ktorKeyMap.getPrivateKey("test")
|
ktorKeyMap.getPrivateKey("test")
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.time.Clock
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
|
|
||||||
class UserRepositoryTest {
|
class UserRepositoryTest {
|
||||||
|
|
||||||
lateinit var db: Database
|
lateinit var db: Database
|
||||||
|
@ -35,7 +34,6 @@ class UserRepositoryTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
transaction(db) {
|
transaction(db) {
|
||||||
|
|
||||||
SchemaUtils.drop(UsersFollowers)
|
SchemaUtils.drop(UsersFollowers)
|
||||||
SchemaUtils.drop(Users)
|
SchemaUtils.drop(Users)
|
||||||
}
|
}
|
||||||
|
@ -43,11 +41,14 @@ class UserRepositoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `findFollowersById フォロワー一覧を取得`() = runTest {
|
fun `findFollowersById フォロワー一覧を取得`() = runTest {
|
||||||
val userRepository = UserRepository(db, object : IdGenerateService {
|
val userRepository = UserRepository(
|
||||||
override suspend fun generateId(): Long {
|
db,
|
||||||
TODO("Not yet implemented")
|
object : IdGenerateService {
|
||||||
|
override suspend fun generateId(): Long {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
val user = userRepository.save(
|
val user = userRepository.save(
|
||||||
User(
|
User(
|
||||||
id = 0L,
|
id = 0L,
|
||||||
|
@ -98,16 +99,18 @@ class UserRepositoryTest {
|
||||||
userRepository.findFollowersById(user.id).let {
|
userRepository.findFollowersById(user.id).let {
|
||||||
assertIterableEquals(listOf(follower, follower2), it)
|
assertIterableEquals(listOf(follower, follower2), it)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `createFollower フォロワー追加`() = runTest {
|
fun `createFollower フォロワー追加`() = runTest {
|
||||||
val userRepository = UserRepository(db, object : IdGenerateService {
|
val userRepository = UserRepository(
|
||||||
override suspend fun generateId(): Long {
|
db,
|
||||||
TODO("Not yet implemented")
|
object : IdGenerateService {
|
||||||
|
override suspend fun generateId(): Long {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
val user = userRepository.save(
|
val user = userRepository.save(
|
||||||
User(
|
User(
|
||||||
0L,
|
0L,
|
||||||
|
@ -140,11 +143,9 @@ class UserRepositoryTest {
|
||||||
)
|
)
|
||||||
userRepository.createFollower(user.id, follower.id)
|
userRepository.createFollower(user.id, follower.id)
|
||||||
transaction {
|
transaction {
|
||||||
|
|
||||||
val followerIds =
|
val followerIds =
|
||||||
UsersFollowers.select { UsersFollowers.userId eq user.id }.map { it[UsersFollowers.followerId] }
|
UsersFollowers.select { UsersFollowers.userId eq user.id }.map { it[UsersFollowers.followerId] }
|
||||||
assertIterableEquals(listOf(follower.id), followerIds)
|
assertIterableEquals(listOf(follower.id), followerIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.time.Instant
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
|
||||||
class UsersAPTest {
|
class UsersAPTest {
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
|
@ -100,8 +99,8 @@ class UsersAPTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Disabled
|
||||||
@Test()
|
@Test()
|
||||||
// @Disabled
|
|
||||||
fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication {
|
fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication {
|
||||||
environment {
|
environment {
|
||||||
config = ApplicationConfig("empty.conf")
|
config = ApplicationConfig("empty.conf")
|
||||||
|
@ -167,16 +166,21 @@ class UsersAPTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Disabled
|
||||||
@Test
|
@Test
|
||||||
// @Disabled
|
|
||||||
fun contentType_Test() {
|
fun contentType_Test() {
|
||||||
|
|
||||||
assertTrue(ContentType.Application.Activity.match("application/activity+json"))
|
assertTrue(ContentType.Application.Activity.match("application/activity+json"))
|
||||||
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity)
|
||||||
assertTrue(listOf.find { contentType ->
|
assertTrue(
|
||||||
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
listOf.find { contentType ->
|
||||||
}.let { it != null })
|
contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
||||||
assertTrue(ContentType.Application.JsonLd.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
|
@Test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package dev.usbharu.hideout.service
|
package dev.usbharu.hideout.service
|
||||||
|
|
||||||
//import kotlinx.coroutines.NonCancellable.message
|
// import kotlinx.coroutines.NonCancellable.message
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -16,17 +16,13 @@ class TwitterSnowflakeIdGenerateServiceTest {
|
||||||
val mutex = Mutex()
|
val mutex = Mutex()
|
||||||
val mutableListOf = mutableListOf<Long>()
|
val mutableListOf = mutableListOf<Long>()
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
|
|
||||||
repeat(500000) {
|
repeat(500000) {
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
val id = TwitterSnowflakeIdGenerateService.generateId()
|
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||||
mutex.withLock {
|
mutex.withLock {
|
||||||
mutableListOf.add(id)
|
mutableListOf.add(id)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,28 +122,30 @@ class ActivityPubFollowServiceImplTest {
|
||||||
mock(),
|
mock(),
|
||||||
activityPubUserService,
|
activityPubUserService,
|
||||||
userService,
|
userService,
|
||||||
HttpClient(MockEngine { httpRequestData ->
|
HttpClient(
|
||||||
assertEquals(person.inbox, httpRequestData.url.toString())
|
MockEngine { httpRequestData ->
|
||||||
val accept = Accept(
|
assertEquals(person.inbox, httpRequestData.url.toString())
|
||||||
type = emptyList(),
|
val accept = Accept(
|
||||||
name = "Follow",
|
|
||||||
`object` = Follow(
|
|
||||||
type = emptyList(),
|
type = emptyList(),
|
||||||
name = "Follow",
|
name = "Follow",
|
||||||
`object` = "https://example.com",
|
`object` = Follow(
|
||||||
actor = "https://follower.example.com"
|
type = emptyList(),
|
||||||
),
|
name = "Follow",
|
||||||
actor = "https://example.com"
|
`object` = "https://example.com",
|
||||||
)
|
actor = "https://follower.example.com"
|
||||||
accept.context += "https://www.w3.org/ns/activitystreams"
|
),
|
||||||
assertEquals(
|
actor = "https://example.com"
|
||||||
accept,
|
|
||||||
Config.configData.objectMapper.readValue<Accept>(
|
|
||||||
httpRequestData.body.toByteArray().decodeToString()
|
|
||||||
)
|
)
|
||||||
)
|
accept.context += "https://www.w3.org/ns/activitystreams"
|
||||||
respondOk()
|
assertEquals(
|
||||||
})
|
accept,
|
||||||
|
Config.configData.objectMapper.readValue<Accept>(
|
||||||
|
httpRequestData.body.toByteArray().decodeToString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
respondOk()
|
||||||
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
activityPubFollowService.receiveFollowJob(
|
activityPubFollowService.receiveFollowJob(
|
||||||
JobProps(
|
JobProps(
|
||||||
|
|
|
@ -73,7 +73,13 @@ class ActivityPubNoteServiceImplTest {
|
||||||
val jobQueueParentService = mock<JobQueueParentService>()
|
val jobQueueParentService = mock<JobQueueParentService>()
|
||||||
val activityPubNoteService = ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService)
|
val activityPubNoteService = ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService)
|
||||||
val postEntity = PostEntity(
|
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)
|
activityPubNoteService.createNote(postEntity)
|
||||||
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
|
verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any())
|
||||||
|
@ -82,17 +88,19 @@ class ActivityPubNoteServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createPostJob 新しい投稿のJob`() = runTest {
|
fun `createPostJob 新しい投稿のJob`() = runTest {
|
||||||
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
|
Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper)
|
||||||
val httpClient = HttpClient(MockEngine { httpRequestData ->
|
val httpClient = HttpClient(
|
||||||
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
|
MockEngine { httpRequestData ->
|
||||||
respondOk()
|
assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString())
|
||||||
})
|
respondOk()
|
||||||
|
}
|
||||||
|
)
|
||||||
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock())
|
val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock())
|
||||||
activityPubNoteService.createNoteJob(
|
activityPubNoteService.createNoteJob(
|
||||||
JobProps(
|
JobProps(
|
||||||
data = mapOf<String, Any>(
|
data = mapOf<String, Any>(
|
||||||
DeliverPostJob.actor.name to "https://follower.example.com",
|
DeliverPostJob.actor.name to "https://follower.example.com",
|
||||||
DeliverPostJob.post.name to "{\"id\":1,\"userId\":1,\"inReplyToId\":null,\"text\":\"test text\"," +
|
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"
|
DeliverPostJob.inbox.name to "https://follower.example.com/inbox"
|
||||||
),
|
),
|
||||||
json = Json
|
json = Json
|
||||||
|
|
|
@ -50,10 +50,8 @@ class UserServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
|
fun `createRemoteUser リモートユーザーを作成できる`() = runTest {
|
||||||
|
|
||||||
Config.configData = ConfigData(domain = "example.com", url = "https://example.com")
|
Config.configData = ConfigData(domain = "example.com", url = "https://example.com")
|
||||||
|
|
||||||
|
|
||||||
val userRepository = mock<IUserRepository> {
|
val userRepository = mock<IUserRepository> {
|
||||||
onBlocking { nextId() } doReturn 113345L
|
onBlocking { nextId() } doReturn 113345L
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import org.jetbrains.exposed.sql.Database
|
||||||
import org.jetbrains.exposed.sql.DatabaseConfig
|
import org.jetbrains.exposed.sql.DatabaseConfig
|
||||||
import org.junit.jupiter.api.extension.ExtendWith
|
import org.junit.jupiter.api.extension.ExtendWith
|
||||||
|
|
||||||
|
|
||||||
@ExtendWith(DBResetInterceptor::class)
|
@ExtendWith(DBResetInterceptor::class)
|
||||||
abstract class DatabaseTestBase {
|
abstract class DatabaseTestBase {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -12,7 +11,8 @@ abstract class DatabaseTestBase {
|
||||||
Database.connect(
|
Database.connect(
|
||||||
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
|
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
|
||||||
driver = "org.h2.Driver",
|
driver = "org.h2.Driver",
|
||||||
databaseConfig = DatabaseConfig { useNestedTransactions = true })
|
databaseConfig = DatabaseConfig { useNestedTransactions = true }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue