StorageComponentTests.swift 2.5 KB

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