Add 2 new tests (PRIVMSG & LIST)
This commit is contained in:
@@ -2,7 +2,6 @@ package com.shr4pnel.ferretirc
|
|||||||
|
|
||||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
@@ -17,14 +16,16 @@ import kotlin.test.assertNotNull
|
|||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
class IrcClientTest {
|
class IrcClientTest {
|
||||||
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var processes: MutableList<Process>
|
lateinit var processes: MutableList<Process>
|
||||||
val client = IrcClient("localhost", 6667)
|
val client = IrcClient("localhost", 6667)
|
||||||
private val logger = KotlinLogging.logger("IrcClientTest")
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
fun setup() {
|
fun setup() = runBlocking {
|
||||||
val logFile = File("src/test/resources/logs/ngircd.log")
|
val logFile = File("src/test/resources/logs/ngircd.log")
|
||||||
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
val ngircdConfigPath = javaClass.classLoader.getResource("ngircd.conf")!!.path
|
||||||
logFile.createNewFile()
|
logFile.createNewFile()
|
||||||
@@ -38,13 +39,8 @@ class IrcClientTest {
|
|||||||
ProcessBuilder("ts", "-s", "%H:%M:%.S").redirectOutput(logFile)
|
ProcessBuilder("ts", "-s", "%H:%M:%.S").redirectOutput(logFile)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
client.scope.launch {
|
client.connect()
|
||||||
client.connect()
|
client.register("shr4p", "Tyler D", "password")
|
||||||
client.register("shr4p", "password")
|
|
||||||
}
|
|
||||||
runBlocking {
|
|
||||||
delay(0.5.seconds)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -93,7 +89,23 @@ class IrcClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun listChannels() = runBlocking {
|
fun listChannels() = runBlocking {
|
||||||
client.queueMessage(Message.List())
|
val channels = client.server.fetchChannels()
|
||||||
delay(1.seconds)
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user