Skip to content

Commit 26563cc

Browse files
authored
[Config] Add Config and ConfigSwift API build tests (#11774)
1 parent 238ccba commit 26563cc

File tree

1 file changed

+233
-0
lines changed

1 file changed

+233
-0
lines changed
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// Copyright 2023 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 XCTest
16+
17+
import FirebaseCore
18+
import FirebaseRemoteConfig
19+
import FirebaseRemoteConfigSwift
20+
21+
final class FirebaseRemoteConfigSwift_APIBuildTests: XCTestCase {
22+
func usage() throws {
23+
// MARK: - FirebaseRemoteConfig
24+
25+
// TODO(ncooke3): These global constants should be lowercase.
26+
let _: String = FirebaseRemoteConfig.NamespaceGoogleMobilePlatform
27+
let _: String = FirebaseRemoteConfig.RemoteConfigThrottledEndTimeInSecondsKey
28+
29+
// TODO(ncooke3): This should probably not be initializable.
30+
FirebaseRemoteConfig.ConfigUpdateListenerRegistration().remove()
31+
32+
let fetchStatus: FirebaseRemoteConfig.RemoteConfigFetchStatus? = nil
33+
switch fetchStatus! {
34+
case .noFetchYet: break
35+
case .success: break
36+
case .failure: break
37+
case .throttled: break
38+
@unknown default: break
39+
}
40+
41+
let fetchAndActivateStatus: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus? = nil
42+
switch fetchAndActivateStatus! {
43+
case .successFetchedFromRemote: break
44+
case .successUsingPreFetchedData: break
45+
case .error: break
46+
@unknown default: break
47+
}
48+
49+
// Used to pass into the intializers for the custom errors below.
50+
let nsError = NSError(domain: "", code: 0, userInfo: nil)
51+
52+
// TODO(ncooke3): Global constants should be lowercase.
53+
let _: String = FirebaseRemoteConfig.RemoteConfigErrorDomain
54+
let _ = FirebaseRemoteConfig.RemoteConfigError(_nsError: nsError)
55+
let _: FirebaseRemoteConfig.RemoteConfigError.Code._ErrorType = FirebaseRemoteConfig
56+
.RemoteConfigError(_nsError: nsError)
57+
let _: String = FirebaseRemoteConfig.RemoteConfigError.errorDomain
58+
let code: FirebaseRemoteConfig.RemoteConfigError.Code? = nil
59+
switch code! {
60+
case .unknown: break
61+
case .throttled: break
62+
case .internalError: break
63+
@unknown default: break
64+
}
65+
_ = FirebaseRemoteConfig.RemoteConfigError.unknown
66+
_ = FirebaseRemoteConfig.RemoteConfigError.throttled
67+
_ = FirebaseRemoteConfig.RemoteConfigError.internalError
68+
69+
// TODO(ncooke3): Global constants should be lowercase.
70+
let _: String = FirebaseRemoteConfig.RemoteConfigUpdateErrorDomain
71+
let _ = FirebaseRemoteConfig.RemoteConfigUpdateError(_nsError: nsError)
72+
let _: FirebaseRemoteConfig.RemoteConfigUpdateError.Code._ErrorType = FirebaseRemoteConfig
73+
.RemoteConfigUpdateError(_nsError: nsError)
74+
let _: String = FirebaseRemoteConfig.RemoteConfigUpdateError.errorDomain
75+
let updateErrorCode: FirebaseRemoteConfig.RemoteConfigUpdateError.Code? = nil
76+
switch updateErrorCode! {
77+
case .streamError: break
78+
case .notFetched: break
79+
case .messageInvalid: break
80+
case .unavailable: break
81+
@unknown default: break
82+
}
83+
_ = FirebaseRemoteConfig.RemoteConfigUpdateError.streamError
84+
_ = FirebaseRemoteConfig.RemoteConfigUpdateError.notFetched
85+
_ = FirebaseRemoteConfig.RemoteConfigUpdateError.messageInvalid
86+
_ = FirebaseRemoteConfig.RemoteConfigUpdateError.unavailable
87+
88+
// TODO(ncooke3): This should probably not be initializable.
89+
let value = FirebaseRemoteConfig.RemoteConfigValue()
90+
let _: String? = value.stringValue
91+
// TODO(ncooke3): Returns an Objective-C reference type.
92+
let _: NSNumber = value.numberValue
93+
let _: Data = value.dataValue
94+
let _: Bool = value.boolValue
95+
let _: Any? = value.jsonValue
96+
97+
let source: FirebaseRemoteConfig.RemoteConfigSource = value.source
98+
switch source {
99+
case .remote: break
100+
case .default: break
101+
case .static: break
102+
@unknown default: break
103+
}
104+
105+
let settings = FirebaseRemoteConfig.RemoteConfigSettings()
106+
settings.minimumFetchInterval = TimeInterval(100)
107+
settings.fetchTimeout = TimeInterval(100)
108+
109+
// TODO(ncooke3): This should probably not be initializable.
110+
let update = FirebaseRemoteConfig.RemoteConfigUpdate()
111+
let _: Set<String> = update.updatedKeys
112+
113+
let _ = FirebaseRemoteConfig.RemoteConfig.remoteConfig()
114+
let config = FirebaseRemoteConfig.RemoteConfig
115+
.remoteConfig(app: FirebaseCore.FirebaseApp.app()!)
116+
let _: Date? = config.lastFetchTime
117+
let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = config.lastFetchStatus
118+
let _: FirebaseRemoteConfig.RemoteConfigSettings = config.configSettings
119+
120+
config.ensureInitialized(completionHandler: { (error: Error?) in })
121+
122+
config.fetch(completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchStatus,
123+
error: Error?) in })
124+
125+
config.fetch()
126+
127+
config.fetch(
128+
withExpirationDuration: TimeInterval(100),
129+
completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchStatus, error: Error?) in
130+
}
131+
)
132+
133+
config.fetch(withExpirationDuration: TimeInterval(100))
134+
135+
config
136+
.fetchAndActivate(
137+
completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus,
138+
error: Error?) in }
139+
)
140+
141+
config.fetchAndActivate()
142+
143+
config.activate(completion: { (success: Bool, error: Error?) in })
144+
145+
config.activate()
146+
147+
if #available(iOS 13.0, *) {
148+
Task {
149+
let _: Void = try await config.ensureInitialized()
150+
let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = try await config.fetch()
151+
let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = try await config
152+
.fetch(withExpirationDuration: TimeInterval(100))
153+
let _: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus = try await config
154+
.fetchAndActivate()
155+
let _: Bool = try await config.activate()
156+
}
157+
}
158+
159+
let _: FirebaseRemoteConfig.RemoteConfigValue = config["key"]
160+
let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: "key")
161+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
162+
let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: nil)
163+
let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(
164+
forKey: "key",
165+
source: source
166+
)
167+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
168+
let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: nil, source: source)
169+
170+
let _: [String] = config.allKeys(from: source)
171+
172+
let _: Set<String> = config.keys(withPrefix: "")
173+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
174+
let _: Set<String> = config.keys(withPrefix: nil)
175+
176+
let defaults: [String: NSObject]? = [:]
177+
config.setDefaults(defaults)
178+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
179+
config.setDefaults(nil)
180+
181+
config.setDefaults(fromPlist: "")
182+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
183+
config.setDefaults(fromPlist: nil)
184+
185+
let _: FirebaseRemoteConfig.RemoteConfigValue? = config.defaultValue(forKey: "")
186+
// TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
187+
let _: FirebaseRemoteConfig.RemoteConfigValue? = config.defaultValue(forKey: nil)
188+
189+
let _: FirebaseRemoteConfig.ConfigUpdateListenerRegistration = config
190+
.addOnConfigUpdateListener(
191+
remoteConfigUpdateCompletion: { (update: FirebaseRemoteConfig.RemoteConfigUpdate?,
192+
error: Error?) in
193+
}
194+
)
195+
196+
// MARK: - FirebaseRemoteConfigSwift
197+
198+
let valueError: FirebaseRemoteConfigSwift
199+
.RemoteConfigValueCodableError = .unsupportedType("foo")
200+
switch valueError {
201+
case .unsupportedType: break
202+
}
203+
204+
let error: FirebaseRemoteConfigSwift.RemoteConfigCodableError = .invalidSetDefaultsInput("foo")
205+
switch error {
206+
case .invalidSetDefaultsInput: break
207+
}
208+
209+
@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *)
210+
struct PropertyWrapperTester {
211+
@FirebaseRemoteConfigSwift.RemoteConfigProperty(key: "", fallback: "")
212+
var stringValue: String!
213+
}
214+
215+
// This should not build because `FirebaseRemoteConfigSwift` does not
216+
// re-export `FirebaseRemoteConfig`.
217+
// let _: FirebaseRemoteConfigSwift.RemoteConfig
218+
219+
struct MyDecodableValue: Decodable {}
220+
let _: MyDecodableValue? = config[decodedValue: ""]
221+
222+
let _: [String: AnyHashable]? = config[jsonValue: ""]
223+
224+
let _: MyDecodableValue = try value.decoded()
225+
let _: MyDecodableValue = try value.decoded(asType: MyDecodableValue.self)
226+
227+
let _: MyDecodableValue? = try config.decoded()
228+
let _: MyDecodableValue? = try config.decoded(asType: MyDecodableValue.self)
229+
230+
struct MyEncodableValue: Encodable {}
231+
let _: Void = try config.setDefaults(from: MyEncodableValue())
232+
}
233+
}

0 commit comments

Comments
 (0)