StorageComponentTests.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2022 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 Foundation
  15. import FirebaseCore
  16. @testable import FirebaseStorage
  17. import FirebaseAppCheckInterop
  18. import FirebaseAuthInterop
  19. import SharedTestUtilities
  20. import XCTest
  21. class StorageComponentTests: StorageTestHelpers {
  22. // MARK: Interoperability Tests
  23. /// Tests that the right number of components are being provided for the container.
  24. func testComponentsBeingRegistered() throws {
  25. let components = StorageComponent.componentsToRegister()
  26. XCTAssert(components.count == 1)
  27. }
  28. /// Tests that a Storage instance can be created properly by the StorageComponent.
  29. func testStorageInstanceCreation() throws {
  30. let component = StorageComponent(app: StorageComponentTests.app)
  31. let storage = component.storage(for: "someBucket")
  32. XCTAssertNotNil(storage)
  33. }
  34. /// Tests that the component container caches instances of StorageComponent.
  35. func testMultipleComponentInstancesCreated() throws {
  36. let registrants = NSMutableSet(array: [StorageComponent.self])
  37. let container = FirebaseComponentContainer(
  38. app: StorageTestHelpers.app,
  39. registrants: registrants
  40. )
  41. let provider1 = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  42. in: container)
  43. XCTAssertNotNil(provider1)
  44. let provider2 = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  45. in: container)
  46. XCTAssertNotNil(provider2)
  47. // Ensure they're the same instance.
  48. XCTAssert(provider1 === provider2)
  49. }
  50. /// Tests that instances of Storage created are different.
  51. func testMultipleStorageInstancesCreated() throws {
  52. let registrants = NSMutableSet(array: [StorageComponent.self])
  53. let container = FirebaseComponentContainer(
  54. app: StorageComponentTests.app,
  55. registrants: registrants
  56. )
  57. let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  58. in: container)
  59. XCTAssertNotNil(provider)
  60. let storage1 = provider.storage(for: "randomBucket")
  61. let storage2 = provider.storage(for: "randomBucket")
  62. XCTAssertNotNil(storage1)
  63. // Ensure they're the same instance.
  64. XCTAssert(storage1 === storage2)
  65. let storage3 = provider.storage(for: "differentBucket")
  66. XCTAssertNotNil(storage3)
  67. XCTAssert(storage1 !== storage3)
  68. }
  69. }