Skip to content

Commit 3a8df40

Browse files
committed
Add testGenerateContent_success_image_emptyPartIgnored
1 parent 4c5e1a0 commit 3a8df40

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

FirebaseAI/Tests/Unit/GenerativeModelVertexAITests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,27 @@ final class GenerativeModelVertexAITests: XCTestCase {
477477
XCTAssertGreaterThan(imagePart.data.count, 0)
478478
}
479479

480+
func testGenerateContent_success_image_emptyPartIgnored() async throws {
481+
MockURLProtocol.requestHandler = try GenerativeModelTestUtil.httpRequestHandler(
482+
forResource: "unary-success-empty-part",
483+
withExtension: "json",
484+
subdirectory: vertexSubdirectory
485+
)
486+
487+
let response = try await model.generateContent(testPrompt)
488+
489+
XCTAssertEqual(response.candidates.count, 1)
490+
let candidate = try XCTUnwrap(response.candidates.first)
491+
XCTAssertEqual(candidate.content.parts.count, 2)
492+
let inlineDataParts = response.inlineDataParts
493+
XCTAssertEqual(inlineDataParts.count, 1)
494+
let imagePart = try XCTUnwrap(inlineDataParts.first)
495+
XCTAssertEqual(imagePart.mimeType, "image/png")
496+
XCTAssertGreaterThan(imagePart.data.count, 0)
497+
let text = try XCTUnwrap(response.text)
498+
XCTAssertTrue(text.starts(with: "I can certainly help you with that"))
499+
}
500+
480501
func testGenerateContent_appCheck_validToken() async throws {
481502
let appCheckToken = "test-valid-token"
482503
model = GenerativeModel(

0 commit comments

Comments
 (0)