Skip to content

Commit

Permalink
VertexAI: update test cases to use full name of mock response files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tanzimfh authored Jul 26, 2024
1 parent 1b49171 commit 0b026b2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class StreamingSnapshotTests {

@Test
fun `short reply`() =
goldenStreamingFile("success-basic-reply-short.txt") {
goldenStreamingFile("streaming-success-basic-reply-short.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -57,7 +57,7 @@ internal class StreamingSnapshotTests {

@Test
fun `long reply`() =
goldenStreamingFile("success-basic-reply-long.txt") {
goldenStreamingFile("streaming-success-basic-reply-long.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -73,7 +73,7 @@ internal class StreamingSnapshotTests {

@Test
fun `unknown enum`() =
goldenStreamingFile("success-unknown-enum.txt") {
goldenStreamingFile("streaming-success-unknown-enum.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -88,7 +88,7 @@ internal class StreamingSnapshotTests {

@Test
fun `unknown enum in finish reason`() =
goldenStreamingFile("failure-unknown-finish-enum.txt") {
goldenStreamingFile("streaming-failure-unknown-finish-enum.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -99,7 +99,7 @@ internal class StreamingSnapshotTests {

@Test
fun `quotes escaped`() =
goldenStreamingFile("success-quotes-escaped.txt") {
goldenStreamingFile("streaming-success-quotes-escaped.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -114,7 +114,7 @@ internal class StreamingSnapshotTests {

@Test
fun `prompt blocked for safety`() =
goldenStreamingFile("failure-prompt-blocked-safety.txt") {
goldenStreamingFile("streaming-failure-prompt-blocked-safety.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -125,23 +125,23 @@ internal class StreamingSnapshotTests {

@Test
fun `empty content`() =
goldenStreamingFile("failure-empty-content.txt") {
goldenStreamingFile("streaming-failure-empty-content.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<SerializationException> { responses.collect() } }
}

@Test
fun `http errors`() =
goldenStreamingFile("failure-http-error.txt", HttpStatusCode.PreconditionFailed) {
goldenStreamingFile("streaming-failure-http-error.txt", HttpStatusCode.PreconditionFailed) {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<ServerException> { responses.collect() } }
}

@Test
fun `stopped for safety`() =
goldenStreamingFile("failure-finish-reason-safety.txt") {
goldenStreamingFile("streaming-failure-finish-reason-safety.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -152,7 +152,7 @@ internal class StreamingSnapshotTests {

@Test
fun `citation parsed correctly`() =
goldenStreamingFile("success-citations.txt") {
goldenStreamingFile("streaming-success-citations.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -163,7 +163,7 @@ internal class StreamingSnapshotTests {

@Test
fun `stopped for recitation`() =
goldenStreamingFile("failure-recitation-no-content.txt") {
goldenStreamingFile("streaming-failure-recitation-no-content.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) {
Expand All @@ -174,39 +174,39 @@ internal class StreamingSnapshotTests {

@Test
fun `image rejected`() =
goldenStreamingFile("failure-image-rejected.txt", HttpStatusCode.BadRequest) {
goldenStreamingFile("streaming-failure-image-rejected.txt", HttpStatusCode.BadRequest) {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<ServerException> { responses.collect() } }
}

@Test
fun `unknown model`() =
goldenStreamingFile("failure-unknown-model.txt", HttpStatusCode.NotFound) {
goldenStreamingFile("streaming-failure-unknown-model.txt", HttpStatusCode.NotFound) {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<ServerException> { responses.collect() } }
}

@Test
fun `invalid api key`() =
goldenStreamingFile("failure-api-key.txt", HttpStatusCode.BadRequest) {
goldenStreamingFile("streaming-failure-api-key.txt", HttpStatusCode.BadRequest) {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<InvalidAPIKeyException> { responses.collect() } }
}

@Test
fun `invalid json`() =
goldenStreamingFile("failure-invalid-json.txt") {
goldenStreamingFile("streaming-failure-invalid-json.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<SerializationException> { responses.collect() } }
}

@Test
fun `malformed content`() =
goldenStreamingFile("failure-malformed-content.txt") {
goldenStreamingFile("streaming-failure-malformed-content.txt") {
val responses = model.generateContentStream("prompt")

withTimeout(testTimeout) { shouldThrow<SerializationException> { responses.collect() } }
Expand Down
Loading

0 comments on commit 0b026b2

Please sign in to comment.