Skip to content

[Infra] Fix remote config linting warnings #14731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions FirebaseRemoteConfig/Tests/Swift/FakeUtils/MockURLProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

class MockURLProtocol: URLProtocol {
#if compiler(>=6)
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
Data,
HTTPURLResponse
))?
#else
static var requestHandler: ((URLRequest) throws -> (
Data,
HTTPURLResponse
))?
#endif

override class func canInit(with request: URLRequest) -> Bool {
#if os(watchOS)
print("MockURLProtocol cannot be used on watchOS.")
return false
#else
return true
#endif // os(watchOS)
}

override class func canonicalRequest(for request: URLRequest) -> URLRequest {
return request
}

override func startLoading() {
guard let requestHandler = MockURLProtocol.requestHandler else {
fatalError("`requestHandler` is nil.")
}
guard let client = client else {
fatalError("`client` is nil.")
}

do {
let (data, respopnse) = try requestHandler(request)
client.urlProtocol(self, didReceive: respopnse, cacheStoragePolicy: .notAllowed)
client.urlProtocol(self, didLoad: data)
client.urlProtocolDidFinishLoading(self)
} catch {
client.urlProtocol(self, didFailWithError: error)
}
}

override func stopLoading() {}
}

This file was deleted.

19 changes: 18 additions & 1 deletion FirebaseRemoteConfig/Tests/Swift/SwiftAPI/APITestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,24 @@ class APITestBase: XCTestCase {
config.configRealtime = RealtimeMocks.mockRealtime(config.configRealtime)
}
fakeConsole = FakeConsole()
config.configFetch.fetchSession = URLSessionMock(with: fakeConsole)
let configuration = URLSessionConfiguration.default
configuration.protocolClasses = [MockURLProtocol.self]
config.configFetch.fetchSession = URLSession(configuration: configuration)

var etag = ""
MockURLProtocol.requestHandler = { request in
let consoleValues = self.fakeConsole.get()
if etag == "" || consoleValues["state"] as! String == RCNFetchResponseKeyStateUpdate {
// Time string in microseconds to insure a different string from previous change.
etag = String(NSDate().timeIntervalSince1970)
}
let jsonData = try! JSONSerialization.data(withJSONObject: consoleValues)
let response = HTTPURLResponse(url: URL(fileURLWithPath: "fakeURL"),
statusCode: 200,
httpVersion: nil,
headerFields: ["etag": etag])
return (jsonData, response!)
}

fakeConsole.config = [Constants.key1: Constants.value1,
Constants.jsonKey: jsonValue,
Expand Down
2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ - (void)testSetCustomSignalsMultipleTimes {
[_configInstances[i] setCustomSignals:testSignals1
withCompletion:^(NSError *_Nullable error) {
XCTAssertNil(error);
[_configInstances[i]
[self->_configInstances[i]
setCustomSignals:testSignals2
withCompletion:^(NSError *_Nullable error) {
XCTAssertNil(error);
Expand Down
3 changes: 1 addition & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,12 @@ case "$product-$platform-$method" in
../../../FirebaseRemoteConfig/Tests/Swift/AccessToken.json

# Integration tests are only run on iOS to minimize flake failures.
# TODO(ncooke3): Remove -sdk and -destination flags.
# TODO(ncooke3): Remove -sdk and -destination flags and replace with "${xcb_flags[@]}"
RunXcodebuild \
-workspace 'gen/FirebaseRemoteConfig/FirebaseRemoteConfig.xcworkspace' \
-scheme "FirebaseRemoteConfig-Unit-swift-api-tests" \
-sdk 'iphonesimulator' \
-destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' \
"${xcb_flags[@]}" \
build \
test
;;
Expand Down
Loading