Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor testGenerateContent_failure_emptyContent with catch let #35

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions Tests/GoogleAITests/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,20 @@ final class GenerativeModelTests: XCTestCase {
withExtension: "json"
)

var responseError: Error?
var content: GenerateContentResponse?
do {
content = try await model.generateContent(testPrompt)
_ = try await model.generateContent(testPrompt)
XCTFail("Should throw GenerateContentError.internalError; no error thrown.")
} catch let GenerateContentError.internalError(underlying: underlyingError) {
guard case let .emptyContent(decodingError) =
try XCTUnwrap(underlyingError as? InvalidCandidateError) else {
XCTFail("Not an InvalidCandidateError.emptyContent error: \(underlyingError)")
return
}
_ = try XCTUnwrap(decodingError as? DecodingError,
"Not a DecodingError: \(decodingError)")
} catch {
responseError = error
XCTFail("Should throw GenerateContentError.internalError; error thrown: \(error)")
}

XCTAssertNil(content)
XCTAssertNotNil(responseError)
let generateContentError = try XCTUnwrap(responseError as? GenerateContentError)
guard case let .internalError(underlyingError) = generateContentError else {
XCTFail("Not an internal error: \(generateContentError)")
return
}
let invalidCandidateError = try XCTUnwrap(underlyingError as? InvalidCandidateError)
guard case let .emptyContent(emptyContentUnderlyingError) = invalidCandidateError else {
XCTFail("Not an empty content error: \(invalidCandidateError)")
return
}
_ = try XCTUnwrap(
emptyContentUnderlyingError as? DecodingError,
"Not a decoding error: \(emptyContentUnderlyingError)"
)
}

func testGenerateContent_failure_finishReasonSafety() async throws {
Expand Down
Loading