@@ -35,6 +35,7 @@ import com.sun.net.httpserver.HttpsConfigurator
35
35
import com.sun.net.httpserver.HttpsServer
36
36
import io.mockk.mockk
37
37
import kotlinx.coroutines.CoroutineScope
38
+ import kotlinx.coroutines.runBlocking
38
39
import okio.buffer
39
40
import okio.source
40
41
import java.io.IOException
@@ -156,10 +157,10 @@ class CoderRestClientTest {
156
157
fun testUnauthorized () {
157
158
val workspace = DataGen .workspace(" ws1" )
158
159
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) } },
163
164
)
164
165
tests.forEach { (endpoint, block) ->
165
166
val (srv, url) = mockServer()
@@ -204,14 +205,14 @@ class CoderRestClientTest {
204
205
)
205
206
206
207
val client = CoderRestClient (context, URL (url), " token" )
207
- assertEquals(user.username, client.me().username)
208
+ assertEquals(user.username, runBlocking { client.me() } .username)
208
209
209
210
val tests = listOf (" invalid" , null )
210
211
tests.forEach { token ->
211
212
val ex =
212
213
assertFailsWith(
213
214
exceptionClass = APIResponseException ::class ,
214
- block = { CoderRestClient (context, URL (url), token).me() },
215
+ block = { runBlocking { CoderRestClient (context, URL (url), token).me() } },
215
216
)
216
217
assertEquals(true , ex.isUnauthorized)
217
218
}
@@ -242,7 +243,7 @@ class CoderRestClientTest {
242
243
exchange.responseBody.write(body)
243
244
},
244
245
)
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 })
246
247
srv.stop(0 )
247
248
}
248
249
}
@@ -326,7 +327,7 @@ class CoderRestClientTest {
326
327
)
327
328
328
329
workspaces.forEach { ws ->
329
- assertEquals(ws.resources, client.resources(ws.workspace))
330
+ assertEquals(ws.resources, runBlocking { client.resources(ws.workspace) } )
330
331
}
331
332
332
333
srv.stop(0 )
@@ -404,7 +405,7 @@ class CoderRestClientTest {
404
405
val ex =
405
406
assertFailsWith(
406
407
exceptionClass = APIResponseException ::class ,
407
- block = { client.updateWorkspace(badWorkspace) },
408
+ block = { runBlocking { client.updateWorkspace(badWorkspace) } },
408
409
)
409
410
assertEquals(
410
411
listOf (
@@ -417,7 +418,7 @@ class CoderRestClientTest {
417
418
actions.clear()
418
419
419
420
with (workspaces[0 ]) {
420
- client.updateWorkspace(this )
421
+ runBlocking { client.updateWorkspace(this @with) }
421
422
val expected =
422
423
listOf (
423
424
Pair (" get_template" , templateID),
@@ -453,7 +454,7 @@ class CoderRestClientTest {
453
454
},
454
455
)
455
456
456
- assertEquals(user.username, client.me().username)
457
+ assertEquals(user.username, runBlocking { client.me() } .username)
457
458
458
459
srv.stop(0 )
459
460
}
@@ -474,7 +475,7 @@ class CoderRestClientTest {
474
475
475
476
assertFailsWith(
476
477
exceptionClass = SSLPeerUnverifiedException ::class ,
477
- block = { client.me() },
478
+ block = { runBlocking { client.me() } },
478
479
)
479
480
480
481
srv.stop(0 )
@@ -494,7 +495,7 @@ class CoderRestClientTest {
494
495
495
496
assertFailsWith(
496
497
exceptionClass = SSLHandshakeException ::class ,
497
- block = { client.me() },
498
+ block = { runBlocking { client.me() } },
498
499
)
499
500
500
501
srv.stop(0 )
@@ -522,7 +523,7 @@ class CoderRestClientTest {
522
523
},
523
524
)
524
525
525
- assertEquals(user.username, client.me().username)
526
+ assertEquals(user.username, runBlocking { client.me() } .username)
526
527
527
528
srv.stop(0 )
528
529
}
@@ -566,7 +567,7 @@ class CoderRestClientTest {
566
567
),
567
568
)
568
569
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 })
570
571
571
572
srv1.stop(0 )
572
573
srv2.stop(0 )
0 commit comments