Skip to content

Commit 20d9c36

Browse files
authored
Minimize signins in VertexAI integration tests (#14697)
1 parent 11fe4a0 commit 20d9c36

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ struct GenerateContentIntegrationTests {
4343
let userID1: String
4444

4545
init() async throws {
46-
let authResult = try await Auth.auth().signIn(
47-
withEmail: Credentials.emailAddress1,
48-
password: Credentials.emailPassword1
49-
)
50-
userID1 = authResult.user.uid
51-
46+
userID1 = try await TestHelpers.getUserID()
5247
storage = Storage.storage()
5348
}
5449

FirebaseVertexAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ struct ImagenIntegrationTests {
3939
var userID1: String
4040

4141
init() async throws {
42-
let authResult = try await Auth.auth().signIn(
43-
withEmail: Credentials.emailAddress1,
44-
password: Credentials.emailPassword1
45-
)
46-
userID1 = authResult.user.uid
47-
42+
userID1 = try await TestHelpers.getUserID()
4843
vertex = VertexAI.vertexAI()
4944
storage = Storage.storage()
5045
}

FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ final class IntegrationTests: XCTestCase {
4848
var userID1 = ""
4949

5050
override func setUp() async throws {
51-
let authResult = try await Auth.auth().signIn(
52-
withEmail: Credentials.emailAddress1,
53-
password: Credentials.emailPassword1
54-
)
55-
userID1 = authResult.user.uid
56-
51+
userID1 = try await TestHelpers.getUserID()
5752
vertex = VertexAI.vertexAI()
5853
model = vertex.generativeModel(
5954
modelName: "gemini-2.0-flash",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FirebaseAuth
16+
import FirebaseCore
17+
18+
enum TestHelpers {
19+
static func getUserID() async throws -> String {
20+
if let user = Auth.auth().currentUser {
21+
return user.uid
22+
} else {
23+
let authResult = try await Auth.auth().signIn(
24+
withEmail: Credentials.emailAddress1,
25+
password: Credentials.emailPassword1
26+
)
27+
return authResult.user.uid
28+
}
29+
}
30+
}

FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
86D77DFE2D7B5C86003D155D /* GoogleService-Info-Spark.plist in Resources */ = {isa = PBXBuildFile; fileRef = 86D77DFD2D7B5C86003D155D /* GoogleService-Info-Spark.plist */; };
2828
86D77E022D7B63AF003D155D /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86D77E012D7B63AC003D155D /* Constants.swift */; };
2929
86D77E042D7B6C9D003D155D /* InstanceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86D77E032D7B6C95003D155D /* InstanceConfig.swift */; };
30+
DEF0BB4F2DA74F680093E9F4 /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */; };
3031
/* End PBXBuildFile section */
3132

3233
/* Begin PBXContainerItemProxy section */
@@ -59,6 +60,7 @@
5960
86D77DFD2D7B5C86003D155D /* GoogleService-Info-Spark.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info-Spark.plist"; sourceTree = "<group>"; };
6061
86D77E012D7B63AC003D155D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
6162
86D77E032D7B6C95003D155D /* InstanceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceConfig.swift; sourceTree = "<group>"; };
63+
DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = "<group>"; };
6264
/* End PBXFileReference section */
6365

6466
/* Begin PBXFrameworksBuildPhase section */
@@ -137,6 +139,7 @@
137139
868A7C572CCC27AF00E449DD /* Integration */ = {
138140
isa = PBXGroup;
139141
children = (
142+
DEF0BB4E2DA74F460093E9F4 /* TestHelpers.swift */,
140143
8689CDCB2D7F8BCF00BF426B /* CountTokensIntegrationTests.swift */,
141144
868A7C4D2CCC1F4700E449DD /* Credentials.swift */,
142145
8661386D2CC943DE00F4B78E /* IntegrationTests.swift */,
@@ -289,6 +292,7 @@
289292
files = (
290293
8689CDCC2D7F8BD700BF426B /* CountTokensIntegrationTests.swift in Sources */,
291294
86D77E042D7B6C9D003D155D /* InstanceConfig.swift in Sources */,
295+
DEF0BB4F2DA74F680093E9F4 /* TestHelpers.swift in Sources */,
292296
868A7C4F2CCC229F00E449DD /* Credentials.swift in Sources */,
293297
864F8F712D4980DD0002EA7E /* ImagenIntegrationTests.swift in Sources */,
294298
862218812D04E098007ED2D4 /* IntegrationTestUtils.swift in Sources */,

0 commit comments

Comments
 (0)