Apply ktlint standard formatting
This commit is contained in:
@@ -5,7 +5,6 @@ import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage as Message
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -14,6 +13,7 @@ import java.lang.ProcessBuilder
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage as Message
|
||||
|
||||
class IrcClientTest {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
@@ -25,87 +25,95 @@ class IrcClientTest {
|
||||
|
||||
@JvmStatic
|
||||
@BeforeAll
|
||||
fun setup() = runBlocking {
|
||||
val logFile = File("src/test/resources/logs/ngircd.log")
|
||||
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
||||
logFile.createNewFile()
|
||||
processes = ProcessBuilder.startPipeline(
|
||||
listOf<ProcessBuilder>(
|
||||
// Run IRC server in [-d] debug log mode, with [-n] no daemon, using config [-f] file at path
|
||||
ProcessBuilder("ngircd", "-dnf", ngircdConfigPath).redirectErrorStream(true),
|
||||
// Remove unhelpful default ngircd info [PID. relative time, GID?]
|
||||
ProcessBuilder("sed", "-ue", "s/\\[[^][]*\\]//g"),
|
||||
// Add relative timestamp
|
||||
ProcessBuilder("ts", "-s", "%H:%M:%.S").redirectOutput(logFile)
|
||||
)
|
||||
)
|
||||
client.connect()
|
||||
client.register("shr4p", "Tyler D", "password")
|
||||
}
|
||||
fun setup() =
|
||||
runBlocking {
|
||||
val logFile = File("src/test/resources/logs/ngircd.log")
|
||||
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
||||
logFile.createNewFile()
|
||||
processes =
|
||||
ProcessBuilder.startPipeline(
|
||||
listOf<ProcessBuilder>(
|
||||
// Run IRC server in [-d] debug log mode, with [-n] no daemon, using config [-f] file at path
|
||||
ProcessBuilder("ngircd", "-dnf", ngircdConfigPath).redirectErrorStream(true),
|
||||
// Remove unhelpful default ngircd info [PID. relative time, GID?]
|
||||
ProcessBuilder("sed", "-ue", "s/\\[[^][]*\\]//g"),
|
||||
// Add relative timestamp
|
||||
ProcessBuilder("ts", "-s", "%H:%M:%.S").redirectOutput(logFile),
|
||||
),
|
||||
)
|
||||
client.connect()
|
||||
client.register("shr4p", "Tyler D", "password")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@AfterAll
|
||||
fun shutdown() = runBlocking {
|
||||
logger.info { "Closing server." }
|
||||
client.queueMessage(Message.Die())
|
||||
client.waitForNext<ServerMessage.Notice>()
|
||||
processes.forEach { it.destroy() }
|
||||
}
|
||||
fun shutdown() =
|
||||
runBlocking {
|
||||
logger.info { "Closing server." }
|
||||
client.queueMessage(Message.Die())
|
||||
client.waitForNext<ServerMessage.Notice>()
|
||||
processes.forEach { it.destroy() }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun sample() {
|
||||
client.scope.launch {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun pingGetsPong() = runBlocking {
|
||||
val token = "ACK"
|
||||
logger.info { "Sending PING $token" }
|
||||
client.queueMessage(Message.Ping(token))
|
||||
fun pingGetsPong() =
|
||||
runBlocking {
|
||||
val token = "ACK"
|
||||
logger.info { "Sending PING $token" }
|
||||
client.queueMessage(Message.Ping(token))
|
||||
|
||||
logger.info { "Waiting to receive PONG" }
|
||||
val pong = withTimeoutOrNull(1.seconds) {
|
||||
client.waitForNext<ServerMessage.Pong> { it.token.equals(token) }
|
||||
logger.info { "Waiting to receive PONG" }
|
||||
val pong =
|
||||
withTimeoutOrNull(1.seconds) {
|
||||
client.waitForNext<ServerMessage.Pong> { it.token.equals(token) }
|
||||
}
|
||||
assertNotNull(pong, "Reached timeout while waiting for PONG")
|
||||
assertEquals(token, pong.token, "Token in PING did not match PONG")
|
||||
logger.info { "Received PING" }
|
||||
}
|
||||
assertNotNull(pong, "Reached timeout while waiting for PONG")
|
||||
assertEquals(token, pong.token, "Token in PING did not match PONG")
|
||||
logger.info { "Received PING" }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun oper() = runBlocking {
|
||||
client.queueMessage(Message.Oper("shr4p", "password"))
|
||||
val mode = withTimeoutOrNull(1.seconds) {
|
||||
client.waitForNext<ServerMessage.Mode>()
|
||||
fun oper() =
|
||||
runBlocking {
|
||||
client.queueMessage(Message.Oper("shr4p", "password"))
|
||||
val mode =
|
||||
withTimeoutOrNull(1.seconds) {
|
||||
client.waitForNext<ServerMessage.Mode>()
|
||||
}
|
||||
assertNotNull(mode, "Timed out waiting for OPER MODE response")
|
||||
assertEquals("shr4p", mode.operatorName, "Received incorrect operator name in MODE")
|
||||
assertEquals("+o", mode.pMask, "Received unexpected mask in MODE")
|
||||
logger.info { "Received MODE with mask ${mode.pMask}" }
|
||||
}
|
||||
assertNotNull(mode, "Timed out waiting for OPER MODE response")
|
||||
assertEquals("shr4p", mode.operatorName, "Received incorrect operator name in MODE")
|
||||
assertEquals("+o", mode.pMask, "Received unexpected mask in MODE")
|
||||
logger.info { "Received MODE with mask ${mode.pMask}" }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listChannels() = runBlocking {
|
||||
val channels = client.server.fetchChannels()
|
||||
assert(channels.isNotEmpty())
|
||||
client.queueMessage(Message.Join(channels.first()))
|
||||
}
|
||||
fun listChannels() =
|
||||
runBlocking {
|
||||
val channels = client.server.fetchChannels()
|
||||
assert(channels.isNotEmpty())
|
||||
client.queueMessage(Message.Join(channels.first()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun messageLands() = runBlocking {
|
||||
val guestUser = IrcClient("localhost", 6667, false)
|
||||
guestUser.connect()
|
||||
guestUser.register("guest", "guest", "pass")
|
||||
val channels = client.server.fetchChannels()
|
||||
val message = Message.PrivMsg(channels.first(), "bring me to life")
|
||||
guestUser.queueMessage(message)
|
||||
val receivedMessage = client.waitForNext<ServerMessage.PrivMsg>()
|
||||
logger.debug { "Message: $message, Received: $receivedMessage" }
|
||||
assertEquals(message.message, receivedMessage.message)
|
||||
assertEquals(message.target.chanName, receivedMessage.targets.first())
|
||||
guestUser.close()
|
||||
}
|
||||
fun messageLands() =
|
||||
runBlocking {
|
||||
val guestUser = IrcClient("localhost", 6667, false)
|
||||
guestUser.connect()
|
||||
guestUser.register("guest", "guest", "pass")
|
||||
val channels = client.server.fetchChannels()
|
||||
val message = Message.PrivMsg(channels.first(), "bring me to life")
|
||||
guestUser.queueMessage(message)
|
||||
val receivedMessage = client.waitForNext<ServerMessage.PrivMsg>()
|
||||
logger.debug { "Message: $message, Received: $receivedMessage" }
|
||||
assertEquals(message.message, receivedMessage.message)
|
||||
assertEquals(message.target.chanName, receivedMessage.targets.first())
|
||||
guestUser.close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user