🚀 Launch 1.0
This commit is contained in:
@@ -1,37 +1,30 @@
|
||||
package dev.solsynth.snConnect
|
||||
|
||||
import dev.solsynth.snConnect.services.SnService
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.logging.Logger
|
||||
|
||||
class WebSocketTest {
|
||||
private val logger = Logger.getLogger(WebSocketTest::class.java.name)
|
||||
suspend fun main() {
|
||||
val service = SnService(
|
||||
baseUrl = "https://api.solian.app", // Replace with actual test server URL
|
||||
clientId = "goatcraft",
|
||||
clientSecret = "testClientSecret",
|
||||
botApiKey = "02-l7ARXnEimQaBY0Dj3SQ.g4UTdShR9GiNWBDjC7qm9Xu83t0Vq8mQ2WPaTO8S-_j6EuKcWd0Kqb_hEkFlahmhfAd5lcH7j_-N8knSIXjo3X7OSFck0E_ogwluZpGSzqbYOrlBAQc9Rk1VhHVNu_W4fi9NR6NnUwpAgyTIh2RuRHk98oVa2I4Ie-NXPybb26N3i9wXv3-wXlkml0IOrhs3FRKMbcJNmKIzEYP0KQNqs3w9TAx0R2fe9DAAQ8WvPW5iPGSbyxr_fF4Qm7tQ0rQvg89x0cUGmKQHtCTeKa2WZi7UBTbw_b4SiHMqpLMxIDQBEZQGqkJ5r37_YCyCNqe5Huha86GG7bT__m6z5emeow"
|
||||
)
|
||||
|
||||
@Test
|
||||
fun testWebSocketConnection() = runBlocking {
|
||||
val service = SnService(
|
||||
baseUrl = "http://localhost:8080", // Replace with actual test server URL
|
||||
clientId = "testClientId",
|
||||
clientSecret = "testClientSecret",
|
||||
botApiKey = "testBotApiKey"
|
||||
)
|
||||
|
||||
// Collect from the flow for a limited time to avoid hanging on failure
|
||||
val packets = withTimeoutOrNull(10000L) { // 10 seconds timeout
|
||||
val collectedPackets = mutableListOf<String>()
|
||||
service.connectWebSocketAsFlow().collect { packet ->
|
||||
collectedPackets.add("Received packet: type=${packet.type}, endpoint=${packet.endpoint}")
|
||||
logger.info(collectedPackets.last())
|
||||
// In a real test, you might check packet contents or behavior
|
||||
}
|
||||
collectedPackets
|
||||
print("server started")
|
||||
// Collect from the flow for a limited time to avoid hanging on failure
|
||||
val packets = withTimeoutOrNull(10000L) { // 10 seconds timeout
|
||||
val collectedPackets = mutableListOf<String>()
|
||||
service.connectWebSocketAsFlow().collect { packet ->
|
||||
collectedPackets.add("Received packet: type=${packet.type}, endpoint=${packet.endpoint}")
|
||||
print(collectedPackets.last())
|
||||
// In a real test, you might check packet contents or behavior
|
||||
}
|
||||
|
||||
// For this test, we're mainly checking that the flow can be created and the setup doesn't crash
|
||||
// In real scenarios, you'd need a WebSocket server running at the specified URL
|
||||
logger.info("WebSocket test finished. Packets received: ${packets?.size ?: 0}")
|
||||
assert(packets != null) // Flow started without immediate error
|
||||
collectedPackets
|
||||
}
|
||||
|
||||
// For this test, we're mainly checking that the flow can be created and the setup doesn't crash
|
||||
// In real scenarios, you'd need a WebSocket server running at the specified URL
|
||||
print("WebSocket test finished. Packets received: ${packets?.size ?: 0}")
|
||||
assert(packets != null) // Flow started without immediate error
|
||||
}
|
||||
|
Reference in New Issue
Block a user