@@ -24,22 +24,21 @@ import XCTest
2424class VertexComponentTests : XCTestCase {
2525 static let projectID = " test-project-id "
2626 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
2732
28- static var app : FirebaseApp ?
33+ return options
34+ } ( )
2935
30- let location = " test-location "
36+ static let app = {
37+ FirebaseApp . configure ( options: options)
38+ return FirebaseApp ( instanceWithName: " test " , options: options)
39+ } ( )
3140
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 "
4342
4443 /// Test that the objc class is available for the component system to update the user agent.
4544 func testComponentsBeingRegistered( ) throws {
@@ -48,27 +47,55 @@ class VertexComponentTests: XCTestCase {
4847
4948 /// Tests that a vertex instance can be created properly.
5049 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)
5451
5552 XCTAssertNotNil ( vertex)
5653 XCTAssertEqual ( vertex. projectID, VertexComponentTests . projectID)
5754 XCTAssertEqual ( vertex. apiKey, VertexComponentTests . apiKey)
5855 XCTAssertEqual ( vertex. location, location)
5956 }
6057
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 {
6360 let app = try XCTUnwrap ( VertexComponentTests . app)
61+
6462 let vertex1 = VertexAI . vertexAI ( app: app, location: location)
6563 let vertex2 = VertexAI . vertexAI ( app: app, location: location)
6664
6765 // Ensure they're the same instance.
6866 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 " )
6996
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.
7299 }
73100
74101 /// Test that vertex instances get deallocated.
0 commit comments