APITestBase.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import FirebaseCore
  15. @testable import FirebaseRemoteConfig
  16. import XCTest
  17. class APITestBase: XCTestCase {
  18. static var useFakeConfig: Bool!
  19. static var mockedFetch: Bool!
  20. var app: FirebaseApp!
  21. var config: RemoteConfig!
  22. var fakeConsole: FakeConsole!
  23. override class func setUp() {
  24. if FirebaseApp.app() == nil {
  25. FirebaseApp.configure()
  26. APITests.mockedFetch = false
  27. }
  28. useFakeConfig = FirebaseApp.app()!.options.projectID == "FakeProject"
  29. }
  30. override func setUp() {
  31. super.setUp()
  32. app = FirebaseApp.app()
  33. config = RemoteConfig.remoteConfig(app: app!)
  34. let settings = RemoteConfigSettings()
  35. settings.minimumFetchInterval = 0
  36. config.configSettings = settings
  37. if APITests.useFakeConfig {
  38. fakeConsole = FakeConsole()
  39. config.configFetch.fetchSession = URLSessionMock(with: fakeConsole)
  40. if !APITests.mockedFetch {
  41. APITests.mockedFetch = true
  42. config.configFetch = FetchMocks.mockFetch(config.configFetch)
  43. }
  44. }
  45. // Uncomment for verbose debug logging.
  46. // FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.debug)
  47. }
  48. override func tearDown() {
  49. if APITests.useFakeConfig {
  50. fakeConsole.empty()
  51. }
  52. app = nil
  53. config = nil
  54. super.tearDown()
  55. }
  56. }