InstanceTests.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2024 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 FirebaseDataConnect
  16. import Foundation
  17. import XCTest
  18. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  19. class InstanceTests: XCTestCase {
  20. var defaultApp: FirebaseApp?
  21. var appTwo: FirebaseApp?
  22. var fakeConnectorConfigOne = ConnectorConfig(
  23. serviceId: "dataconnect",
  24. location: "us-central1",
  25. connector: "kitchensink"
  26. )
  27. var fakeConnectorConfigTwo = ConnectorConfig(
  28. serviceId: "dataconnect",
  29. location: "us-central1",
  30. connector: "blogs"
  31. )
  32. override func setUp() {
  33. let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
  34. gcmSenderID: "00000000000000000-00000000000-000000000")
  35. options.projectID = "fdc-test"
  36. FirebaseApp.configure(options: options)
  37. defaultApp = FirebaseApp.app()
  38. let optionsTwo = FirebaseOptions(
  39. googleAppID: "0:0000000000001:ios:0000000000000001",
  40. gcmSenderID: "00000000000000000-00000000000-000000001"
  41. )
  42. optionsTwo.projectID = "fdc-test"
  43. FirebaseApp.configure(name: "app-two", options: optionsTwo)
  44. appTwo = FirebaseApp.app(name: "app-two")
  45. }
  46. // same connector config, same app, instance returned should be same
  47. func testSameInstance() throws {
  48. let dcOne = DataConnect.dataConnect(connectorConfig: fakeConnectorConfigOne)
  49. let dcTwo = DataConnect.dataConnect(connectorConfig: fakeConnectorConfigOne)
  50. let isSameInstance = dcOne === dcTwo
  51. XCTAssertTrue(isSameInstance)
  52. }
  53. // same connector config, different apps, instances should be different
  54. func testDifferentInstanceDifferentApps() throws {
  55. let dcOne = DataConnect.dataConnect(connectorConfig: fakeConnectorConfigOne)
  56. let dcTwo = DataConnect.dataConnect(app: appTwo, connectorConfig: fakeConnectorConfigTwo)
  57. let isDifferent = dcOne !== dcTwo
  58. XCTAssertTrue(isDifferent)
  59. }
  60. }