Skip to content

Commit 6ce436f

Browse files
committed
Get fake console tests working
1 parent b0dcf33 commit 6ce436f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

FirebaseRemoteConfig/SwiftNew/ConfigFetch.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ extension Installations: InstallationsProtocol {}
103103
/// Guard the read/write operation.
104104
private let lockQueue: DispatchQueue
105105

106-
private let installations: (any InstallationsProtocol)?
106+
public var installations: (any InstallationsProtocol)?
107107

108108
/// Provide fetchSession for tests to override.
109109
/// - Note: Managed internally by the fetch instance.
110-
@objc public var fetchSession: any RCNConfigFetchSession
110+
public var fetchSession: any RCNConfigFetchSession
111111

112112
private let namespace: String
113113

@@ -180,8 +180,13 @@ extension Installations: InstallationsProtocol {}
180180
super.init()
181181
}
182182

183+
public var disableNetworkSessionRecreation: Bool = false
184+
183185
/// Add the ability to update NSURLSession's timeout after a session has already been created.
184186
@objc public func recreateNetworkSession() {
187+
if disableNetworkSessionRecreation {
188+
return
189+
}
185190
fetchSession.invalidateAndCancel()
186191
fetchSession = configuredFetchSessionProvider(settings)
187192
}

FirebaseRemoteConfig/Tests/Swift/FakeUtils/URLSessionPartialMock.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class URLSessionMock: URLSession, @unchecked Sendable {
4545
var response: URLResponse?
4646
var etag = ""
4747

48+
override func invalidateAndCancel() {
49+
// Do nothing
50+
}
51+
4852
override func dataTask(with request: URLRequest,
4953
completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void)
5054
-> URLSessionDataTask {

FirebaseRemoteConfig/Tests/Swift/SwiftAPI/APITestBase.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
import FirebaseCore
16+
import FirebaseInstallations
1617
import FirebaseRemoteConfig
1718

1819
#if SWIFT_PACKAGE
@@ -21,6 +22,16 @@ import FirebaseRemoteConfig
2122

2223
import XCTest
2324

25+
class InstallationsFake: InstallationsProtocol {
26+
func authToken(completion: @escaping (InstallationsAuthTokenResult?, (any Error)?) -> Void) {
27+
completion(nil, nil)
28+
}
29+
30+
func installationID(completion: @escaping (String?, (any Error)?) -> Void) {
31+
completion("fake_installation_id", nil)
32+
}
33+
}
34+
2435
class APITestBase: XCTestCase {
2536
static var useFakeConfig: Bool!
2637
static var mockedFetch: Bool!
@@ -80,14 +91,15 @@ class APITestBase: XCTestCase {
8091
if APITests.useFakeConfig {
8192
if !APITests.mockedFetch {
8293
APITests.mockedFetch = true
83-
config.configFetch = FetchMocks.mockFetch(config.configFetch)
94+
config.configFetch.installations = InstallationsFake()
8495
}
8596
if !APITests.mockedRealtime {
8697
APITests.mockedRealtime = true
8798
config.configRealtime = RealtimeMocks.mockRealtime(config.configRealtime)
8899
}
89100
fakeConsole = FakeConsole()
90101
config.configFetch.fetchSession = URLSessionMock(with: fakeConsole)
102+
config.configFetch.disableNetworkSessionRecreation = true
91103

92104
fakeConsole.config = [Constants.key1: Constants.value1,
93105
Constants.jsonKey: jsonValue,

0 commit comments

Comments
 (0)