From e3e82cc2d2e0813c8fb35437d0a9f9b42d31d351 Mon Sep 17 00:00:00 2001 From: Chris Araman Date: Thu, 6 May 2021 13:26:11 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Remove=20unused=20test=20h?= =?UTF-8?q?elpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/NetworkSessionMock.swift | 15 ------- .../Network/TestURLSessionDelegate.swift | 41 ------------------- .../URLSessionConfiguration+Tests.swift | 31 -------------- .../Network/URLSessionDataTaskMock.swift | 24 ----------- Tests/MasKitTests/Strongify.swift | 14 +------ 5 files changed, 1 insertion(+), 124 deletions(-) delete mode 100644 Tests/MasKitTests/Network/TestURLSessionDelegate.swift delete mode 100644 Tests/MasKitTests/Network/URLSessionConfiguration+Tests.swift delete mode 100644 Tests/MasKitTests/Network/URLSessionDataTaskMock.swift diff --git a/Tests/MasKitTests/Network/NetworkSessionMock.swift b/Tests/MasKitTests/Network/NetworkSessionMock.swift index f168cfd..76556b7 100644 --- a/Tests/MasKitTests/Network/NetworkSessionMock.swift +++ b/Tests/MasKitTests/Network/NetworkSessionMock.swift @@ -19,21 +19,6 @@ class NetworkSessionMock: NetworkSession { var data: Data? var error: Error? - /// Creates a mock data task - /// - /// - Parameters: - /// - url: unused - /// - completionHandler: Closure which is delivered both data and error properties (only one should be non-nil) - /// - Returns: Mock data task - func dataTask(with _: URL, completionHandler: @escaping CompletionHandler) -> URLSessionDataTask { - let data = self.data - let error = self.error - - return URLSessionDataTaskMock { - completionHandler(data, nil, error) - } - } - /// Immediately passes data and error to completion handler. /// /// - Parameters: diff --git a/Tests/MasKitTests/Network/TestURLSessionDelegate.swift b/Tests/MasKitTests/Network/TestURLSessionDelegate.swift deleted file mode 100644 index 872d820..0000000 --- a/Tests/MasKitTests/Network/TestURLSessionDelegate.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// TestURLSessionDelegate.swift -// MasKitTests -// -// Created by Ben Chatelain on 1/5/19. -// Copyright © 2019 mas-cli. All rights reserved. -// - -import Foundation - -/// Delegate for network requests initiated from tests. -class TestURLSessionDelegate: NSObject, URLSessionDelegate { - func urlSession( - _: URLSession, - didReceive challenge: URLAuthenticationChallenge, - completionHandler: ( - URLSession.AuthChallengeDisposition, - URLCredential? - ) -> Void - ) { - // For example, you may want to override this to accept some self-signed certs here. - let methodIsServerTrust = challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust - if methodIsServerTrust, Constants.selfSignedHosts.contains(challenge.protectionSpace.host) { - // Allow the self-signed cert. - let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!) - completionHandler(.useCredential, credential) - } else { - // You *have* to call completionHandler, so call - // it to do the default action. - completionHandler(.performDefaultHandling, nil) - } - } - - enum Constants { - // A list of hosts you allow self-signed certificates on. - // You'd likely have your dev/test servers here. - // Please don't put your production server here! - static let selfSignedHosts: Set = - ["dev.example.com", "test.example.com"] - } -} diff --git a/Tests/MasKitTests/Network/URLSessionConfiguration+Tests.swift b/Tests/MasKitTests/Network/URLSessionConfiguration+Tests.swift deleted file mode 100644 index 06fc2c7..0000000 --- a/Tests/MasKitTests/Network/URLSessionConfiguration+Tests.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// URLSessionConfiguration+Test.swift -// MasKitTests -// -// Created by Ben Chatelain on 1/5/19. -// Copyright © 2019 mas-cli. All rights reserved. -// - -import Foundation - -/// Configuration for network requests initiated from tests. -extension URLSessionConfiguration { - /// Just like defaultSessionConfiguration, returns a - /// newly created session configuration object, customised - /// from the default to your requirements. - class func testSessionConfiguration() -> URLSessionConfiguration { - let config = `default` - - // Eg we think 60s is too long a timeout time. - config.timeoutIntervalForRequest = 20 - - // Some headers that are common to all reqeuests. - // Eg my backend needs to be explicitly asked for JSON. - config.httpAdditionalHeaders = ["MyResponseType": "JSON"] - - // Eg we want to use pipelining. - config.httpShouldUsePipelining = true - - return config - } -} diff --git a/Tests/MasKitTests/Network/URLSessionDataTaskMock.swift b/Tests/MasKitTests/Network/URLSessionDataTaskMock.swift deleted file mode 100644 index 648f25e..0000000 --- a/Tests/MasKitTests/Network/URLSessionDataTaskMock.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// URLSessionDataTaskMock .swift -// MasKitTests -// -// Created by Ben Chatelain on 1/5/19. -// Copyright © 2019 mas-cli. All rights reserved. -// - -import Foundation - -// Partial mock subclassing the original class -class URLSessionDataTaskMock: URLSessionDataTask { - private let closure: () -> Void - - init(closure: @escaping () -> Void) { - self.closure = closure - } - - // We override the 'resume' method and simply call our closure - // instead of actually resuming any task. - override func resume() { - closure() - } -} diff --git a/Tests/MasKitTests/Strongify.swift b/Tests/MasKitTests/Strongify.swift index 3e58d8f..6ab81fd 100644 --- a/Tests/MasKitTests/Strongify.swift +++ b/Tests/MasKitTests/Strongify.swift @@ -8,19 +8,7 @@ // https://medium.com/@merowing_/stop-weak-strong-dance-in-swift-3aec6d3563d4 -func strongify( - _ context: Context?, - closure: @escaping (Context, Arguments) -> Void -) -> (Arguments) -> Void { - let strongified = { [weak context] (arguments: Arguments) in - guard let strongContext = context else { return } - closure(strongContext, arguments) - } - - return strongified -} - -func strongify(_ context: Context?, closure: @escaping (Context) -> Void) { +func strongify(_ context: Context?, closure: (Context) -> Void) { guard let strongContext = context else { return } closure(strongContext) }