From 444fabec94c39d61887b75f9659125179dcca4ba Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 5 Oct 2024 22:41:00 +0900 Subject: [PATCH] Fix failing tests caused by extension cache --- .../KingfisherManagerTests.swift | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Tests/KingfisherTests/KingfisherManagerTests.swift b/Tests/KingfisherTests/KingfisherManagerTests.swift index 4f53c100a..391ceb6ad 100644 --- a/Tests/KingfisherTests/KingfisherManagerTests.swift +++ b/Tests/KingfisherTests/KingfisherManagerTests.swift @@ -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)) @@ -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)) @@ -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) } @@ -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) @@ -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)