StorageComponentTests.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: XCTestCase {
  22. static var app: FirebaseApp!
  23. override class func setUp() {
  24. let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
  25. gcmSenderID: "00000000000000000-00000000000-000000000")
  26. options.projectID = "myProjectID"
  27. app = FirebaseApp(instanceWithName: "test", options: options)
  28. }
  29. // MARK: Interoperability Tests
  30. /// Tests that the right number of components are being provided for the container.
  31. func testComponentsBeingRegistered() throws {
  32. let components = StorageComponent.componentsToRegister()
  33. XCTAssert(components.count == 1)
  34. }
  35. /// Tests that a Storage instance can be created properly by the StorageComponent.
  36. func testStorageInstanceCreation() throws {
  37. let component = StorageComponent(app: StorageComponentTests.app)
  38. let storage = component.storage(for: "someBucket")
  39. XCTAssertNotNil(storage)
  40. }
  41. /// Tests that the component container caches instances of StorageComponent.
  42. func testMultipleComponentInstancesCreated() throws {
  43. let registrants = NSMutableSet(array: [StorageComponent.self])
  44. let container = FirebaseComponentContainer(
  45. app: StorageComponentTests.app,
  46. registrants: registrants
  47. )
  48. let provider1 = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  49. in: container)
  50. XCTAssertNotNil(provider1)
  51. let provider2 = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  52. in: container)
  53. XCTAssertNotNil(provider2)
  54. // Ensure they're the same instance.
  55. XCTAssert(provider1 === provider2)
  56. }
  57. /// Tests that instances of Storage created are different.
  58. func testMultipleStorageInstancesCreated() throws {
  59. let registrants = NSMutableSet(array: [StorageComponent.self])
  60. let container = FirebaseComponentContainer(
  61. app: StorageComponentTests.app,
  62. registrants: registrants
  63. )
  64. let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
  65. in: container)
  66. XCTAssertNotNil(provider)
  67. let storage1 = provider.storage(for: "randomBucket")
  68. let storage2 = provider.storage(for: "randomBucket")
  69. XCTAssertNotNil(storage1)
  70. // Ensure they're the same instance.
  71. XCTAssert(storage1 === storage2)
  72. let storage3 = provider.storage(for: "differentBucket")
  73. XCTAssertNotNil(storage3)
  74. XCTAssert(storage1 !== storage3)
  75. }
  76. }