@@ -24,22 +24,21 @@ import XCTest
24
24
class VertexComponentTests : XCTestCase {
25
25
static let projectID = " test-project-id "
26
26
static let apiKey = " test-api-key "
27
+ static let options = {
28
+ let options = FirebaseOptions ( googleAppID: " 0:0000000000000:ios:0000000000000000 " ,
29
+ gcmSenderID: " 00000000000000000-00000000000-000000000 " )
30
+ options. projectID = VertexComponentTests . projectID
31
+ options. apiKey = VertexComponentTests . apiKey
27
32
28
- static var app : FirebaseApp ?
33
+ return options
34
+ } ( )
29
35
30
- let location = " test-location "
36
+ static let app = {
37
+ FirebaseApp . configure ( options: options)
38
+ return FirebaseApp ( instanceWithName: " test " , options: options)
39
+ } ( )
31
40
32
- override class func setUp( ) {
33
- super. setUp ( )
34
- if app == nil {
35
- let options = FirebaseOptions ( googleAppID: " 0:0000000000000:ios:0000000000000000 " ,
36
- gcmSenderID: " 00000000000000000-00000000000-000000000 " )
37
- options. projectID = VertexComponentTests . projectID
38
- options. apiKey = VertexComponentTests . apiKey
39
- FirebaseApp . configure ( options: options)
40
- app = FirebaseApp ( instanceWithName: " test " , options: options)
41
- }
42
- }
41
+ let location = " test-location "
43
42
44
43
/// Test that the objc class is available for the component system to update the user agent.
45
44
func testComponentsBeingRegistered( ) throws {
@@ -48,27 +47,55 @@ class VertexComponentTests: XCTestCase {
48
47
49
48
/// Tests that a vertex instance can be created properly.
50
49
func testVertexInstanceCreation( ) throws {
51
- let app = try XCTUnwrap ( VertexComponentTests . app)
52
-
53
- let vertex = VertexAI . vertexAI ( app: app, location: location)
50
+ let vertex = VertexAI . vertexAI ( app: VertexComponentTests . app, location: location)
54
51
55
52
XCTAssertNotNil ( vertex)
56
53
XCTAssertEqual ( vertex. projectID, VertexComponentTests . projectID)
57
54
XCTAssertEqual ( vertex. apiKey, VertexComponentTests . apiKey)
58
55
XCTAssertEqual ( vertex. location, location)
59
56
}
60
57
61
- /// Tests that a vertex instances are reused properly.
62
- func testMultipleComponentInstancesCreated ( ) throws {
58
+ /// Tests that Vertex instances are reused properly.
59
+ func testSameAppAndLocation_instanceReused ( ) throws {
63
60
let app = try XCTUnwrap ( VertexComponentTests . app)
61
+
64
62
let vertex1 = VertexAI . vertexAI ( app: app, location: location)
65
63
let vertex2 = VertexAI . vertexAI ( app: app, location: location)
66
64
67
65
// Ensure they're the same instance.
68
66
XCTAssert ( vertex1 === vertex2)
67
+ }
68
+
69
+ func testSameAppAndDifferentLocation_newInstanceCreated( ) throws {
70
+ let vertex1 = VertexAI . vertexAI ( app: VertexComponentTests . app, location: location)
71
+ let vertex2 = VertexAI . vertexAI ( app: VertexComponentTests . app, location: " differentLocation " )
72
+
73
+ // Ensure they are different instances.
74
+ XCTAssert ( vertex1 !== vertex2)
75
+ }
76
+
77
+ func testDifferentAppAndSameLocation_newInstanceCreated( ) throws {
78
+ FirebaseApp . configure ( name: " test-2 " , options: VertexComponentTests . options)
79
+ let app2 = FirebaseApp ( instanceWithName: " test-2 " , options: VertexComponentTests . options)
80
+ addTeardownBlock { await app2. delete ( ) }
81
+
82
+ let vertex1 = VertexAI . vertexAI ( app: VertexComponentTests . app, location: location)
83
+ let vertex2 = VertexAI . vertexAI ( app: app2, location: location)
84
+
85
+ XCTAssert ( VertexComponentTests . app != app2)
86
+ XCTAssert ( vertex1 !== vertex2) // Ensure they are different instances.
87
+ }
88
+
89
+ func testDifferentAppAndDifferentLocation_newInstanceCreated( ) throws {
90
+ FirebaseApp . configure ( name: " test-2 " , options: VertexComponentTests . options)
91
+ let app2 = FirebaseApp ( instanceWithName: " test-2 " , options: VertexComponentTests . options)
92
+ addTeardownBlock { await app2. delete ( ) }
93
+
94
+ let vertex1 = VertexAI . vertexAI ( app: VertexComponentTests . app, location: location)
95
+ let vertex2 = VertexAI . vertexAI ( app: app2, location: " differentLocation " )
69
96
70
- let vertex3 = VertexAI . vertexAI ( app: app , location : " differentLocation " )
71
- XCTAssert ( vertex1 !== vertex3 )
97
+ XCTAssert ( VertexComponentTests . app != app2 )
98
+ XCTAssert ( vertex1 !== vertex2 ) // Ensure they are different instances.
72
99
}
73
100
74
101
/// Test that vertex instances get deallocated.
0 commit comments