Skip to content

Commit

Permalink
Fix failing tests caused by extension cache
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Oct 5, 2024
1 parent bf2039e commit 444fabe
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions Tests/KingfisherTests/KingfisherManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,11 @@ class KingfisherManagerTests: XCTestCase {
func testMissingResourceOfLivePhotoNotFound() async throws {
let resource = KF.ImageResource(downloadURL: LivePhotoURL.mov)

try await manager.cache.storeToDisk(testImageData, forKey: resource.cacheKey)
try await manager.cache.storeToDisk(
testImageData,
forKey: resource.cacheKey,
forcedExtension: resource.downloadURL.pathExtension
)

let source = LivePhotoSource(resources: [resource])
let missing = manager.missingResources(source, options: .init(.empty))
Expand All @@ -1374,7 +1378,11 @@ class KingfisherManagerTests: XCTestCase {
let resource1 = KF.ImageResource(downloadURL: LivePhotoURL.heic)
let resource2 = KF.ImageResource(downloadURL: LivePhotoURL.mov)

try await manager.cache.storeToDisk(testImageData, forKey: resource1.cacheKey)
try await manager.cache.storeToDisk(
testImageData,
forKey: resource1.cacheKey,
forcedExtension: resource1.downloadURL.pathExtension
)

let source = LivePhotoSource(resources: [resource1, resource2])
let missing = manager.missingResources(source, options: .init(.empty))
Expand All @@ -1399,8 +1407,14 @@ class KingfisherManagerTests: XCTestCase {
XCTAssertTrue(urls.contains(LivePhotoURL.mov))
XCTAssertTrue(urls.contains(LivePhotoURL.heic))

let resourceCached1 = manager.cache.imageCachedType(forKey: resource1.cacheKey)
let resourceCached2 = manager.cache.imageCachedType(forKey: resource1.cacheKey)
let resourceCached1 = manager.cache.imageCachedType(
forKey: resource1.cacheKey,
forcedExtension: resource1.downloadURL.pathExtension
)
let resourceCached2 = manager.cache.imageCachedType(
forKey: resource2.cacheKey,
forcedExtension: resource2.downloadURL.pathExtension
)
XCTAssertEqual(resourceCached1, .disk)
XCTAssertEqual(resourceCached2, .disk)
}
Expand Down Expand Up @@ -1443,21 +1457,25 @@ class KingfisherManagerTests: XCTestCase {
try await manager.cache.storeToDisk(
testImageData,
forKey: resource1.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource1.downloadURL.pathExtension
)
try await manager.cache.storeToDisk(
testImageData,
forKey: resource2.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource2.downloadURL.pathExtension
)

let resource1Cached = manager.cache.isCached(
forKey: resource1.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource1.downloadURL.pathExtension
)
let resource2Cached = manager.cache.isCached(
forKey: resource2.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource2.downloadURL.pathExtension
)
XCTAssertTrue(resource1Cached)
XCTAssertTrue(resource2Cached)
Expand All @@ -1482,17 +1500,20 @@ class KingfisherManagerTests: XCTestCase {
try await manager.cache.storeToDisk(
testImageData,
forKey: resource1.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource1.downloadURL.pathExtension
)
stub(resource2.downloadURL, data: testImageData)

let resource1Cached = manager.cache.isCached(
forKey: resource1.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource1.downloadURL.pathExtension
)
let resource2Cached = manager.cache.isCached(
forKey: resource2.cacheKey,
processorIdentifier: LivePhotoImageProcessor.default.identifier
processorIdentifier: LivePhotoImageProcessor.default.identifier,
forcedExtension: resource2.downloadURL.pathExtension
)
XCTAssertTrue(resource1Cached)
XCTAssertFalse(resource2Cached)
Expand Down

0 comments on commit 444fabe

Please sign in to comment.