瀏覽代碼

Add extension file store test

onevcat 1 年之前
父節點
當前提交
126e2d094e
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. 18 0
      Tests/KingfisherTests/ImageCacheTests.swift

+ 18 - 0
Tests/KingfisherTests/ImageCacheTests.swift

@@ -762,6 +762,24 @@ class ImageCacheTests: XCTestCase {
         XCTAssertEqual(newSize, UInt(testImagePNGData.count * testKeys.count))
     }
     
+    func testStoreFileWithForcedExtension() async throws {
+        let key = testKeys[0]
+        try await cache.store(testImage, forKey: key, forcedExtension: "jpg", toDisk: true)
+    
+        let pathWithoutExtension = cache.cachePath(forKey: key)
+        XCTAssertFalse(FileManager.default.fileExists(atPath: pathWithoutExtension))
+        
+        let pathWithExtension = cache.cachePath(forKey: key, forcedExtension: "jpg")
+        XCTAssertTrue(FileManager.default.fileExists(atPath: pathWithExtension))
+        
+        XCTAssertEqual(cache.imageCachedType(forKey: key), .memory)
+        XCTAssertEqual(cache.imageCachedType(forKey: key, forcedExtension: "jpg"), .memory)
+        
+        cache.clearMemoryCache()
+        XCTAssertEqual(cache.imageCachedType(forKey: key), .none)
+        XCTAssertEqual(cache.imageCachedType(forKey: key, forcedExtension: "jpg"), .disk)
+    }
+    
     // MARK: - Helper
     private func storeMultipleImages(_ completionHandler: @escaping () -> Void) {
         let group = DispatchGroup()