@@ -35,6 +35,7 @@ import com.sun.net.httpserver.HttpsConfigurator
3535import com.sun.net.httpserver.HttpsServer
3636import io.mockk.mockk
3737import kotlinx.coroutines.CoroutineScope
38+ import kotlinx.coroutines.runBlocking
3839import okio.buffer
3940import okio.source
4041import java.io.IOException
@@ -156,10 +157,10 @@ class CoderRestClientTest {
156157 fun testUnauthorized () {
157158 val workspace = DataGen .workspace(" ws1" )
158159 val tests = listOf<Pair <String , (CoderRestClient ) - > Unit >> (
159- " /api/v2/workspaces" to { it.workspaces() },
160- " /api/v2/users/me" to { it.me() },
161- " /api/v2/buildinfo" to { it.buildInfo() },
162- " /api/v2/templates/${workspace.templateID} " to { it.updateWorkspace(workspace) },
160+ " /api/v2/workspaces" to { runBlocking { it.workspaces() } },
161+ " /api/v2/users/me" to { runBlocking { it.me() } },
162+ " /api/v2/buildinfo" to { runBlocking { it.buildInfo() } },
163+ " /api/v2/templates/${workspace.templateID} " to { runBlocking { it.updateWorkspace(workspace) } },
163164 )
164165 tests.forEach { (endpoint, block) ->
165166 val (srv, url) = mockServer()
@@ -204,14 +205,14 @@ class CoderRestClientTest {
204205 )
205206
206207 val client = CoderRestClient (context, URL (url), " token" )
207- assertEquals(user.username, client.me().username)
208+ assertEquals(user.username, runBlocking { client.me() } .username)
208209
209210 val tests = listOf (" invalid" , null )
210211 tests.forEach { token ->
211212 val ex =
212213 assertFailsWith(
213214 exceptionClass = APIResponseException ::class ,
214- block = { CoderRestClient (context, URL (url), token).me() },
215+ block = { runBlocking { CoderRestClient (context, URL (url), token).me() } },
215216 )
216217 assertEquals(true , ex.isUnauthorized)
217218 }
@@ -242,7 +243,7 @@ class CoderRestClientTest {
242243 exchange.responseBody.write(body)
243244 },
244245 )
245- assertEquals(workspaces.map { ws -> ws.name }, client.workspaces().map { ws -> ws.name })
246+ assertEquals(workspaces.map { ws -> ws.name }, runBlocking { client.workspaces() } .map { ws -> ws.name })
246247 srv.stop(0 )
247248 }
248249 }
@@ -326,7 +327,7 @@ class CoderRestClientTest {
326327 )
327328
328329 workspaces.forEach { ws ->
329- assertEquals(ws.resources, client.resources(ws.workspace))
330+ assertEquals(ws.resources, runBlocking { client.resources(ws.workspace) } )
330331 }
331332
332333 srv.stop(0 )
@@ -404,7 +405,7 @@ class CoderRestClientTest {
404405 val ex =
405406 assertFailsWith(
406407 exceptionClass = APIResponseException ::class ,
407- block = { client.updateWorkspace(badWorkspace) },
408+ block = { runBlocking { client.updateWorkspace(badWorkspace) } },
408409 )
409410 assertEquals(
410411 listOf (
@@ -417,7 +418,7 @@ class CoderRestClientTest {
417418 actions.clear()
418419
419420 with (workspaces[0 ]) {
420- client.updateWorkspace(this )
421+ runBlocking { client.updateWorkspace(this @with) }
421422 val expected =
422423 listOf (
423424 Pair (" get_template" , templateID),
@@ -453,7 +454,7 @@ class CoderRestClientTest {
453454 },
454455 )
455456
456- assertEquals(user.username, client.me().username)
457+ assertEquals(user.username, runBlocking { client.me() } .username)
457458
458459 srv.stop(0 )
459460 }
@@ -474,7 +475,7 @@ class CoderRestClientTest {
474475
475476 assertFailsWith(
476477 exceptionClass = SSLPeerUnverifiedException ::class ,
477- block = { client.me() },
478+ block = { runBlocking { client.me() } },
478479 )
479480
480481 srv.stop(0 )
@@ -494,7 +495,7 @@ class CoderRestClientTest {
494495
495496 assertFailsWith(
496497 exceptionClass = SSLHandshakeException ::class ,
497- block = { client.me() },
498+ block = { runBlocking { client.me() } },
498499 )
499500
500501 srv.stop(0 )
@@ -522,7 +523,7 @@ class CoderRestClientTest {
522523 },
523524 )
524525
525- assertEquals(user.username, client.me().username)
526+ assertEquals(user.username, runBlocking { client.me() } .username)
526527
527528 srv.stop(0 )
528529 }
@@ -566,7 +567,7 @@ class CoderRestClientTest {
566567 ),
567568 )
568569
569- assertEquals(workspaces.map { ws -> ws.name }, client.workspaces().map { ws -> ws.name })
570+ assertEquals(workspaces.map { ws -> ws.name }, runBlocking { client.workspaces() } .map { ws -> ws.name })
570571
571572 srv1.stop(0 )
572573 srv2.stop(0 )
0 commit comments