Skip to content

Commit 0b5185a

Browse files
authored
[Infra] Fix remote config linting warnings (#14731)
1 parent 7ea4e9d commit 0b5185a

File tree

5 files changed

+82
-69
lines changed

5 files changed

+82
-69
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2020 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+
class MockURLProtocol: URLProtocol {
18+
#if compiler(>=6)
19+
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
20+
Data,
21+
HTTPURLResponse
22+
))?
23+
#else
24+
static var requestHandler: ((URLRequest) throws -> (
25+
Data,
26+
HTTPURLResponse
27+
))?
28+
#endif
29+
30+
override class func canInit(with request: URLRequest) -> Bool {
31+
#if os(watchOS)
32+
print("MockURLProtocol cannot be used on watchOS.")
33+
return false
34+
#else
35+
return true
36+
#endif // os(watchOS)
37+
}
38+
39+
override class func canonicalRequest(for request: URLRequest) -> URLRequest {
40+
return request
41+
}
42+
43+
override func startLoading() {
44+
guard let requestHandler = MockURLProtocol.requestHandler else {
45+
fatalError("`requestHandler` is nil.")
46+
}
47+
guard let client = client else {
48+
fatalError("`client` is nil.")
49+
}
50+
51+
do {
52+
let (data, respopnse) = try requestHandler(request)
53+
client.urlProtocol(self, didReceive: respopnse, cacheStoragePolicy: .notAllowed)
54+
client.urlProtocol(self, didLoad: data)
55+
client.urlProtocolDidFinishLoading(self)
56+
} catch {
57+
client.urlProtocol(self, didFailWithError: error)
58+
}
59+
}
60+
61+
override func stopLoading() {}
62+
}

FirebaseRemoteConfig/Tests/Swift/FakeUtils/URLSessionPartialMock.swift

Lines changed: 0 additions & 65 deletions
This file was deleted.

FirebaseRemoteConfig/Tests/Swift/SwiftAPI/APITestBase.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,24 @@ class APITestBase: XCTestCase {
8888
config.configRealtime = RealtimeMocks.mockRealtime(config.configRealtime)
8989
}
9090
fakeConsole = FakeConsole()
91-
config.configFetch.fetchSession = URLSessionMock(with: fakeConsole)
91+
let configuration = URLSessionConfiguration.default
92+
configuration.protocolClasses = [MockURLProtocol.self]
93+
config.configFetch.fetchSession = URLSession(configuration: configuration)
94+
95+
var etag = ""
96+
MockURLProtocol.requestHandler = { request in
97+
let consoleValues = self.fakeConsole.get()
98+
if etag == "" || consoleValues["state"] as! String == RCNFetchResponseKeyStateUpdate {
99+
// Time string in microseconds to insure a different string from previous change.
100+
etag = String(NSDate().timeIntervalSince1970)
101+
}
102+
let jsonData = try! JSONSerialization.data(withJSONObject: consoleValues)
103+
let response = HTTPURLResponse(url: URL(fileURLWithPath: "fakeURL"),
104+
statusCode: 200,
105+
httpVersion: nil,
106+
headerFields: ["etag": etag])
107+
return (jsonData, response!)
108+
}
92109

93110
fakeConsole.config = [Constants.key1: Constants.value1,
94111
Constants.jsonKey: jsonValue,

FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ - (void)testSetCustomSignalsMultipleTimes {
19161916
[_configInstances[i] setCustomSignals:testSignals1
19171917
withCompletion:^(NSError *_Nullable error) {
19181918
XCTAssertNil(error);
1919-
[_configInstances[i]
1919+
[self->_configInstances[i]
19201920
setCustomSignals:testSignals2
19211921
withCompletion:^(NSError *_Nullable error) {
19221922
XCTAssertNil(error);

scripts/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,12 @@ case "$product-$platform-$method" in
486486
../../../FirebaseRemoteConfig/Tests/Swift/AccessToken.json
487487

488488
# Integration tests are only run on iOS to minimize flake failures.
489-
# TODO(ncooke3): Remove -sdk and -destination flags.
489+
# TODO(ncooke3): Remove -sdk and -destination flags and replace with "${xcb_flags[@]}"
490490
RunXcodebuild \
491491
-workspace 'gen/FirebaseRemoteConfig/FirebaseRemoteConfig.xcworkspace' \
492492
-scheme "FirebaseRemoteConfig-Unit-swift-api-tests" \
493493
-sdk 'iphonesimulator' \
494494
-destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' \
495-
"${xcb_flags[@]}" \
496495
build \
497496
test
498497
;;

0 commit comments

Comments
 (0)