Skip to content

Commit 6106f13

Browse files
committed
Restore and update tests
1 parent 63b91e0 commit 6106f13

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2022 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 Foundation
16+
17+
import FirebaseCore
18+
@testable import FirebaseStorage
19+
20+
import FirebaseAppCheckInterop
21+
import FirebaseAuthInterop
22+
import SharedTestUtilities
23+
24+
import XCTest
25+
26+
class StorageComponentTests: StorageTestHelpers {
27+
/// Test that the objc class is available for the component system to update the user agent.
28+
func testComponentsBeingRegistered() throws {
29+
XCTAssertNotNil(NSClassFromString("FIRStorage"))
30+
}
31+
32+
/// Tests that a Storage instance can be created properly.
33+
func testStorageInstanceCreation() throws {
34+
let app = try XCTUnwrap(StorageComponentTests.app)
35+
let storage1 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
36+
XCTAssertNotNil(storage1)
37+
}
38+
39+
/// Tests that a Storage instances are reused properly.
40+
func testMultipleComponentInstancesCreated() throws {
41+
let app = try XCTUnwrap(StorageComponentTests.app)
42+
let storage1 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
43+
let storage2 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
44+
45+
// Ensure they're the same instance.
46+
XCTAssert(storage1 === storage2)
47+
48+
let storage3 = Storage.storage(app: app, url: "gs://foo-baz.appspot.com")
49+
XCTAssert(storage1 !== storage3)
50+
}
51+
52+
/// Test that Storage instances get deallocated.
53+
func testStorageLifecycle() throws {
54+
weak var weakApp: FirebaseApp?
55+
weak var weakStorage: Storage?
56+
try autoreleasepool {
57+
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
58+
gcmSenderID: "00000000000000000-00000000000-000000000")
59+
options.projectID = "myProjectID"
60+
let app1 = FirebaseApp(instanceWithName: "transitory app", options: options)
61+
weakApp = try XCTUnwrap(app1)
62+
let storage = Storage(app: app1, bucket: "transitory bucket")
63+
weakStorage = storage
64+
XCTAssertNotNil(weakStorage)
65+
}
66+
XCTAssertNil(weakApp)
67+
XCTAssertNil(weakStorage)
68+
}
69+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2024 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 Foundation
16+
17+
import FirebaseCore
18+
@testable import FirebaseVertexAI
19+
20+
import SharedTestUtilities
21+
22+
import XCTest
23+
24+
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
25+
class VertexComponentTests: XCTestCase {
26+
static var app: FirebaseApp!
27+
28+
override class func setUp() {
29+
super.setUp()
30+
if app == nil {
31+
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
32+
gcmSenderID: "00000000000000000-00000000000-000000000")
33+
options.projectID = "myProjectID"
34+
FirebaseApp.configure(options: options)
35+
app = FirebaseApp(instanceWithName: "test", options: options)
36+
}
37+
}
38+
39+
/// Test that the objc class is available for the component system to update the user agent.
40+
func testComponentsBeingRegistered() throws {
41+
XCTAssertNotNil(NSClassFromString("FIRVertexAIComponent"))
42+
}
43+
44+
/// Tests that a vertex instance can be created properly.
45+
func testVertexInstanceCreation() throws {
46+
let app = try XCTUnwrap(VertexComponentTests.app)
47+
let vertex = VertexAI.vertexAI(app: app, location: "my-location")
48+
XCTAssertNotNil(vertex)
49+
}
50+
51+
/// Tests that a vertex instances are reused properly.
52+
func testMultipleComponentInstancesCreated() throws {
53+
let app = try XCTUnwrap(VertexComponentTests.app)
54+
let vertex1 = VertexAI.vertexAI(app: app, location: "my-location")
55+
let vertex2 = VertexAI.vertexAI(app: app, location: "my-location")
56+
57+
// Ensure they're the same instance.
58+
XCTAssert(vertex1 === vertex2)
59+
60+
let vertex3 = VertexAI.vertexAI(app: app, location: "differentLocation")
61+
XCTAssert(vertex1 !== vertex3)
62+
}
63+
64+
/// Test that vertex instances get deallocated.
65+
func testVertexLifecycle() throws {
66+
weak var weakApp: FirebaseApp?
67+
weak var weakVertex: VertexAI?
68+
try autoreleasepool {
69+
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
70+
gcmSenderID: "00000000000000000-00000000000-000000000")
71+
options.projectID = "myProjectID"
72+
let app1 = FirebaseApp(instanceWithName: "transitory app", options: options)
73+
weakApp = try XCTUnwrap(app1)
74+
let vertex = VertexAI(app: app1, location: "transitory location")
75+
weakVertex = vertex
76+
XCTAssertNotNil(weakVertex)
77+
}
78+
XCTAssertNil(weakApp)
79+
XCTAssertNil(weakVertex)
80+
}
81+
}

0 commit comments

Comments
 (0)