FakeConsoleTests.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 FakeConsoleTests: APITestBase {
  18. override func setUp() {
  19. super.setUp()
  20. fakeConsole.config = ["Key1": "Value1"]
  21. }
  22. // Test New API.
  23. // Contrast with testUnchangedActivateWillFlag in APITests.swift.
  24. func testChangedActivateWillNotFlag() {
  25. let expectation = self.expectation(description: #function)
  26. config.fetch { status, error in
  27. if let error = error {
  28. XCTFail("Fetch Error \(error)")
  29. }
  30. XCTAssertEqual(status, RemoteConfigFetchStatus.success)
  31. self.config.activate { changed, error in
  32. XCTAssertNil(error)
  33. XCTAssertTrue(changed)
  34. XCTAssertEqual(self.config["Key1"].stringValue, "Value1")
  35. expectation.fulfill()
  36. }
  37. }
  38. waitForExpectations()
  39. // Simulate updating console.
  40. fakeConsole.config = ["Key1": "Value2"]
  41. let expectation2 = self.expectation(description: #function + "2")
  42. config.fetch { status, error in
  43. if let error = error {
  44. XCTFail("Fetch Error \(error)")
  45. }
  46. XCTAssertEqual(status, RemoteConfigFetchStatus.success)
  47. self.config.activate { changed, error in
  48. XCTAssertNil(error)
  49. XCTAssert(changed)
  50. XCTAssertEqual(self.config["Key1"].stringValue, "Value2")
  51. expectation2.fulfill()
  52. }
  53. }
  54. waitForExpectations()
  55. }
  56. private func waitForExpectations() {
  57. let kFIRStorageIntegrationTestTimeout = 10.0
  58. waitForExpectations(timeout: kFIRStorageIntegrationTestTimeout,
  59. handler: { (error) -> Void in
  60. if let error = error {
  61. print(error)
  62. }
  63. })
  64. }
  65. }