Skip to content

Commit 5011009

Browse files
committed
Add FirebaseAuth
1 parent c50ccda commit 5011009

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

FirebaseVertexAI/Tests/TestApp/IntegrationTests/IntegrationTests.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import FirebaseAuth
1516
import FirebaseCore
1617
import FirebaseVertexAI
1718
import XCTest
@@ -40,12 +41,27 @@ final class IntegrationTests: XCTestCase {
4041
var vertex: VertexAI!
4142
var model: GenerativeModel!
4243

44+
static let emailEnvVar = "VERTEXAI_INTEGRATION_AUTH_EMAIL_1"
45+
static let passwordEnvVar = "VERTEXAI_INTEGRATION_AUTH_EMAIL_1_PW"
46+
4347
override func setUp() async throws {
44-
try XCTSkipIf(ProcessInfo.processInfo.environment["VertexAIRunIntegrationTests"] == nil, """
48+
let environment = ProcessInfo.processInfo.environment
49+
try XCTSkipIf(environment["VertexAIRunIntegrationTests"] == nil, """
4550
Vertex AI integration tests skipped; to enable them, set the VertexAIRunIntegrationTests \
4651
environment variable in Xcode or CI jobs.
4752
""")
4853

54+
let email = try XCTUnwrap(
55+
environment[IntegrationTests.emailEnvVar],
56+
"No email address specified in environment variable \(IntegrationTests.emailEnvVar)."
57+
)
58+
let password = try XCTUnwrap(
59+
environment[IntegrationTests.passwordEnvVar],
60+
"No email address specified in environment variable \(IntegrationTests.passwordEnvVar)."
61+
)
62+
63+
try await Auth.auth().signIn(withEmail: email, password: password)
64+
4965
vertex = VertexAI.vertexAI()
5066
model = vertex.generativeModel(
5167
modelName: "gemini-1.5-flash",
@@ -57,10 +73,6 @@ final class IntegrationTests: XCTestCase {
5773
)
5874
}
5975

60-
func testShouldFail() {
61-
XCTFail("This should fail if the tests are being run.")
62-
}
63-
6476
// MARK: - Generate Content
6577

6678
func testGenerateContent() async throws {
@@ -122,6 +134,18 @@ final class IntegrationTests: XCTestCase {
122134
XCTAssertEqual(response.totalBillableCharacters, 35)
123135
}
124136

137+
func testCountTokens_userAuth_fileData() async throws {
138+
let fileData = FileDataPart(
139+
uri: "gs://ios-opensource-samples.appspot.com/vertexai/authenticated/user/6FwXhmYnM8VBr655PrQQiWfxqiS2/red.webp",
140+
mimeType: "image/jpeg"
141+
)
142+
143+
let response = try await model.countTokens(fileData)
144+
145+
XCTAssertEqual(response.totalTokens, 266)
146+
XCTAssertEqual(response.totalBillableCharacters, 35)
147+
}
148+
125149
func testCountTokens_functionCalling() async throws {
126150
let sumDeclaration = FunctionDeclaration(
127151
name: "sum",

0 commit comments

Comments
 (0)