Skip to content

Commit d42b17d

Browse files
committed
Add Stdio coverage for integration tests
1 parent 41fc351 commit d42b17d

32 files changed

+2228
-1727
lines changed
Lines changed: 302 additions & 98 deletions
Large diffs are not rendered by default.
Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import kotlin.test.assertEquals
2020
import kotlin.test.assertNotNull
2121
import kotlin.test.assertTrue
2222

23-
class ResourceEdgeCasesTest : KotlinTestBase() {
23+
abstract class AbstractResourceIntegrationTest : KotlinTestBase() {
2424

2525
private val testResourceUri = "test://example.txt"
2626
private val testResourceName = "Test Resource"
@@ -67,6 +67,31 @@ class ResourceEdgeCasesTest : KotlinTestBase() {
6767
)
6868
}
6969

70+
server.setRequestHandler<SubscribeRequest>(Method.Defined.ResourcesSubscribe) { _, _ ->
71+
EmptyRequestResult()
72+
}
73+
74+
server.setRequestHandler<UnsubscribeRequest>(Method.Defined.ResourcesUnsubscribe) { _, _ ->
75+
EmptyRequestResult()
76+
}
77+
78+
server.addResource(
79+
uri = testResourceUri,
80+
name = testResourceName,
81+
description = testResourceDescription,
82+
mimeType = "text/plain",
83+
) { request ->
84+
ReadResourceResult(
85+
contents = listOf(
86+
TextResourceContents(
87+
text = testResourceContent,
88+
uri = request.uri,
89+
mimeType = "text/plain",
90+
),
91+
),
92+
)
93+
}
94+
7095
server.addResource(
7196
uri = binaryResourceUri,
7297
name = binaryResourceName,
@@ -117,13 +142,41 @@ class ResourceEdgeCasesTest : KotlinTestBase() {
117142
),
118143
)
119144
}
145+
}
120146

121-
server.setRequestHandler<SubscribeRequest>(Method.Defined.ResourcesSubscribe) { _, _ ->
122-
EmptyRequestResult()
123-
}
147+
@Test
148+
fun testListResources() = runBlocking(Dispatchers.IO) {
149+
val result = client.listResources()
124150

125-
server.setRequestHandler<UnsubscribeRequest>(Method.Defined.ResourcesUnsubscribe) { _, _ ->
126-
EmptyRequestResult()
151+
assertNotNull(result, "List resources result should not be null")
152+
assertTrue(result.resources.isNotEmpty(), "Resources list should not be empty")
153+
154+
val testResource = result.resources.find { it.uri == testResourceUri }
155+
assertNotNull(testResource, "Test resource should be in the list")
156+
assertEquals(testResourceName, testResource.name, "Resource name should match")
157+
assertEquals(testResourceDescription, testResource.description, "Resource description should match")
158+
}
159+
160+
@Test
161+
fun testReadResource() = runBlocking(Dispatchers.IO) {
162+
val result = client.readResource(ReadResourceRequest(uri = testResourceUri))
163+
164+
assertNotNull(result, "Read resource result should not be null")
165+
assertTrue(result.contents.isNotEmpty(), "Resource contents should not be empty")
166+
167+
val content = result.contents.firstOrNull() as? TextResourceContents
168+
assertNotNull(content, "Resource content should be TextResourceContents")
169+
assertEquals(testResourceContent, content.text, "Resource content should match")
170+
}
171+
172+
@Test
173+
fun testSubscribeAndUnsubscribe() {
174+
runBlocking(Dispatchers.IO) {
175+
val subscribeResult = client.subscribeResource(SubscribeRequest(uri = testResourceUri))
176+
assertNotNull(subscribeResult, "Subscribe result should not be null")
177+
178+
val unsubscribeResult = client.unsubscribeResource(UnsubscribeRequest(uri = testResourceUri))
179+
assertNotNull(unsubscribeResult, "Unsubscribe result should not be null")
127180
}
128181
}
129182

@@ -257,15 +310,4 @@ class ResourceEdgeCasesTest : KotlinTestBase() {
257310
assertTrue(result.contents.isNotEmpty(), "Result contents should not be empty")
258311
}
259312
}
260-
261-
@Test
262-
fun testSubscribeAndUnsubscribe() {
263-
runBlocking(Dispatchers.IO) {
264-
val subscribeResult = client.subscribeResource(SubscribeRequest(uri = testResourceUri))
265-
assertNotNull(subscribeResult, "Subscribe result should not be null")
266-
267-
val unsubscribeResult = client.unsubscribeResource(UnsubscribeRequest(uri = testResourceUri))
268-
assertNotNull(unsubscribeResult, "Unsubscribe result should not be null")
269-
}
270-
}
271313
}

0 commit comments

Comments
 (0)