StorageMetadataTests.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 FirebaseStorage
  16. import XCTest
  17. class StorageMetadataTests: XCTestCase {
  18. func testReflexiveMetadataEquality() {
  19. let metaDict = ["bucket": "bucket", "name": "/path/to/file"]
  20. let metadata0 = StorageMetadata(dictionary: metaDict)
  21. let metadata1 = metadata0
  22. XCTAssertEqual(metadata0, metadata1)
  23. }
  24. func testMetadataEquality() {
  25. let metaDict = [
  26. "bucket": "bucket",
  27. "name": "/path/to/file",
  28. "md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
  29. ]
  30. let metadata0 = StorageMetadata(dictionary: metaDict)
  31. let metadata1 = StorageMetadata(dictionary: metaDict)
  32. XCTAssertEqual(metadata0, metadata1)
  33. }
  34. func testMetadataMd5Inequality() {
  35. let metaDict0 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427e"]
  36. let metaDict1 = ["md5Hash": "d41d8cd98f00b204e9800998ecf8427f"]
  37. let metadata0 = StorageMetadata(dictionary: metaDict0)
  38. let metadata1 = StorageMetadata(dictionary: metaDict1)
  39. XCTAssertNotEqual(metadata0, metadata1)
  40. }
  41. func testMetadataCopy() {
  42. let metaDict = [
  43. "bucket": "bucket",
  44. "name": "/path/to/file",
  45. "md5Hash": "d41d8cd98f00b204e9800998ecf8427e",
  46. ]
  47. let metadata0 = StorageMetadata(dictionary: metaDict)
  48. let metadata1 = metadata0.copy() as? StorageMetadata
  49. // Verify that copied object has a new reference.
  50. XCTAssertFalse(metadata0 === metadata1)
  51. XCTAssertEqual(metadata0, metadata1)
  52. }
  53. }