StorageComponentTests.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  22. class StorageComponentTests: StorageTestHelpers {
  23. /// Test that the objc class is available for the component system to update the user agent.
  24. func testComponentsBeingRegistered() throws {
  25. XCTAssertNotNil(NSClassFromString("FIRStorage"))
  26. }
  27. /// Tests that a Storage instance can be created properly.
  28. func testStorageInstanceCreation() throws {
  29. let app = try XCTUnwrap(app)
  30. let storage1 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
  31. XCTAssertNotNil(storage1)
  32. }
  33. /// Tests that a Storage instances are reused properly.
  34. func testMultipleComponentInstancesCreated() throws {
  35. let app = try XCTUnwrap(app)
  36. let storage1 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
  37. let storage2 = Storage.storage(app: app, url: "gs://foo-bar.appspot.com")
  38. // Ensure they're the same instance.
  39. XCTAssert(storage1 === storage2)
  40. let storage3 = Storage.storage(app: app, url: "gs://foo-baz.appspot.com")
  41. XCTAssert(storage1 !== storage3)
  42. }
  43. /// Test that Storage instances get deallocated.
  44. func testStorageLifecycle() throws {
  45. weak var weakApp: FirebaseApp?
  46. weak var weakStorage: Storage?
  47. try autoreleasepool {
  48. let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
  49. gcmSenderID: "00000000000000000-00000000000-000000000")
  50. options.projectID = "myProjectID"
  51. let app1 = FirebaseApp(instanceWithName: "transitory app", options: options)
  52. weakApp = try XCTUnwrap(app1)
  53. let storage = Storage(app: app1, bucket: "transitory bucket")
  54. weakStorage = storage
  55. XCTAssertNotNil(weakStorage)
  56. }
  57. XCTAssertNil(weakApp)
  58. XCTAssertNil(weakStorage)
  59. }
  60. }