import Observation import XCTest @testable import OldFella final class AvatarTestProtocol: URLProtocol { static let calls = FeedCallCounter() override static func canInit(with request: URLRequest) -> Bool { true } override static func canonicalRequest(for request: URLRequest) -> URLRequest { request } override func startLoading() { _ = Self.calls.next() let url = request.url! let response = HTTPURLResponse( url: url, statusCode: url.path == "/error" ? 503 : 200, httpVersion: "HTTP/1.1", headerFields: ["Cache-Control": "max-age=3600"])! client?.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed) let data = UIGraphicsImageRenderer(size: CGSize(width: 2, height: 2)).image { _ in UIColor.red.setFill() UIRectFill(CGRect(x: 0, y: 0, width: 2, height: 2)) }.pngData()! client?.urlProtocol(self, didLoad: data) client?.urlProtocolDidFinishLoading(self) } override func stopLoading() {} }