Skip to content

Commit

Permalink
chore(tests): add more tests for streaming (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jan 13, 2025
1 parent bebfa9c commit 5dec143
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.openai.core.http.Headers
import com.openai.core.http.HttpResponse
import com.openai.core.http.SseMessage
import com.openai.core.jsonMapper
import com.openai.errors.OpenAIException
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.nio.charset.StandardCharsets
Expand All @@ -21,6 +22,25 @@ class SseHandlerTest {
internal val expectedMessages: List<SseMessage>? = null,
internal val expectedException: Exception? = null
) {
DATA_MISSING_EVENT(
buildString {
append("data: {\"foo\":true}\n")
append("\n")
},
listOf(sseMessageBuilder().data("{\"foo\":true}").build())
),
MULTIPLE_DATA_MISSING_EVENT(
buildString {
append("data: {\"foo\":true}\n")
append("\n")
append("data: {\"bar\":false}\n")
append("\n")
},
listOf(
sseMessageBuilder().data("{\"foo\":true}").build(),
sseMessageBuilder().data("{\"bar\":false}").build()
)
),
DATA_JSON_ESCAPED_DOUBLE_NEW_LINE(
buildString {
append("data: {\n")
Expand Down Expand Up @@ -60,6 +80,27 @@ class SseHandlerTest {
append("\n")
},
listOf(sseMessageBuilder().data("{\"content\":\"известни\"}").build())
),
STRING_ERROR_PROPERTY(
buildString {
append("data: {\"error\":\"ERROR!\"}\n")
append("\n")
},
expectedException = OpenAIException("ERROR!")
),
ERROR_PROPERTY_WITH_MESSAGE(
buildString {
append("data: {\"error\":{\"message\":\"ERROR!\"}}\n")
append("\n")
},
expectedException = OpenAIException("ERROR!")
),
ERROR_PROPERTY_MALFORMED(
buildString {
append("data: {\"error\":42}\n")
append("\n")
},
expectedException = OpenAIException("An error occurred during streaming")
)
}

Expand Down

0 comments on commit 5dec143

Please sign in to comment.