Skip to content

Commit

Permalink
Add tests for AVAsset provider cacheKey
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Oct 27, 2023
1 parent d2fe2c0 commit 0a2213c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tests/KingfisherTests/ImageDataProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ class ImageDataProviderTests: XCTestCase {
XCTAssertTrue(called)
}

func testAVAssetImageDataProviderCacheKeyVariesForRemote() {
let remoteURL1 = URL(string: "https://example.com/1/hello.mp4")!
let remoteURL2 = URL(string: "https://example.com/2/hello.mp4")!

let provider1 = AVAssetImageDataProvider(assetURL: remoteURL1, seconds: 10)
XCTAssertEqual(provider1.cacheKey, "https://example.com/1/hello.mp4_10.0")

let provider2 = AVAssetImageDataProvider(assetURL: remoteURL2, seconds: 10)
XCTAssertNotEqual(provider1.cacheKey, provider2.cacheKey)
}

// AVAssetImageDataProvider fix for appending to #1825
func testAVAssetImageDataProviderCacheKeyConsistForDifferentAppSandbox() {
let localURL1 = URL(string: "file:///Users/onevcat/Library/Developer/CoreSimulator/Devices/ABC/data/Containers/Bundle/Application/DEF/Kingfisher-Demo.app/video/hello.mp4")!
let localURL2 = URL(string: "file:///Users/onevcat/Library/Developer/CoreSimulator/Devices/ABC/data/Containers/Bundle/Application/XYZ/Kingfisher-Demo.app/video/hello.mp4")!

let provider1 = AVAssetImageDataProvider(assetURL: localURL1, seconds: 10)
XCTAssertEqual(provider1.cacheKey, "\(URL.localFileCacheKeyPrefix)/Kingfisher-Demo.app/video/hello.mp4_10.0")

let provider2 = AVAssetImageDataProvider(assetURL: localURL2, seconds: 10)
XCTAssertEqual(provider1.cacheKey, provider2.cacheKey)
}

#if swift(>=5.5)
#if canImport(_Concurrency)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand Down

0 comments on commit 0a2213c

Please sign in to comment.