@@ -18,6 +18,7 @@ import androidx.test.platform.app.InstrumentationRegistry
1818import app.cash.turbine.test
1919import app.cash.turbine.turbineScope
2020import com.amazonaws.sdk.appsync.core.authorizers.ApiKeyAuthorizer
21+ import com.amazonaws.sdk.appsync.events.data.ConnectException
2122import com.amazonaws.sdk.appsync.events.data.InvalidInputException
2223import com.amazonaws.sdk.appsync.events.data.PublishResult
2324import com.amazonaws.sdk.appsync.events.data.UnauthorizedException
@@ -47,6 +48,7 @@ import org.junit.Test
4748internal class EventsWebSocketClientTests {
4849 private val eventsConfig = getEventsConfig(InstrumentationRegistry .getInstrumentation().targetContext)
4950 private val apiKeyAuthorizer = ApiKeyAuthorizer (eventsConfig.apiKey)
51+ private val badApiKeyAuthorizer = ApiKeyAuthorizer (" bad-api-key" )
5052 private val webSocketLogCapture = EventsLibraryLogCapture ()
5153 private val defaultChannel = " default/${UUID .randomUUID()} "
5254 private val customChannel = " custom/${UUID .randomUUID()} "
@@ -60,6 +62,12 @@ internal class EventsWebSocketClientTests {
6062 loggerProvider = { _ -> webSocketLogCapture }
6163 )
6264 )
65+
66+ private val badWebSocketClient = events.createWebSocketClient(
67+ badApiKeyAuthorizer,
68+ badApiKeyAuthorizer,
69+ badApiKeyAuthorizer
70+ )
6371 private val backgroundScope = CoroutineScope (Dispatchers .IO )
6472
6573 @After
@@ -109,6 +117,15 @@ internal class EventsWebSocketClientTests {
109117 )
110118 }
111119
120+ @Test
121+ fun testConnectionFailure () = runBlockingWithTimeout {
122+ turbineScope(timeout = 10 .seconds) {
123+ badWebSocketClient.subscribe(defaultChannel).test(timeout = 10 .seconds) {
124+ awaitError() shouldBe ConnectException (UnauthorizedException ())
125+ }
126+ }
127+ }
128+
112129 @Test
113130 fun testPublishWithBadAuth (): Unit = runBlockingWithTimeout {
114131 // Publish the message
0 commit comments