diff options
| author | Andrew Bulhak <andrew.bulhak@mullvad.net> | 2024-02-06 11:44:27 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-02-07 15:13:22 +0100 |
| commit | 95d9a485801c52060e8ccd10981dccfa8da58718 (patch) | |
| tree | e6f45def8b04489207c5b0e5651b3e7a164df0b5 | |
| parent | 6c5110520336ab7ed1ffff1952ffa3a9bb794ea7 (diff) | |
| download | mullvadvpn-95d9a485801c52060e8ccd10981dccfa8da58718.tar.xz mullvadvpn-95d9a485801c52060e8ccd10981dccfa8da58718.zip | |
SwiftFormat pass
| -rw-r--r-- | ios/MullvadVPNTests/Mocks/MockTunnel.swift | 37 | ||||
| -rw-r--r-- | ios/MullvadVPNTests/Mocks/MockTunnelInteractor.swift | 57 | ||||
| -rw-r--r-- | ios/MullvadVPNTests/StartTunnelOperationTests.swift | 63 | ||||
| -rw-r--r-- | ios/Shared/ApplicationTarget.swift | 3 |
4 files changed, 83 insertions, 77 deletions
diff --git a/ios/MullvadVPNTests/Mocks/MockTunnel.swift b/ios/MullvadVPNTests/Mocks/MockTunnel.swift index df53c7092c..b9daa63c87 100644 --- a/ios/MullvadVPNTests/Mocks/MockTunnel.swift +++ b/ios/MullvadVPNTests/Mocks/MockTunnel.swift @@ -11,49 +11,50 @@ import NetworkExtension class MockTunnel: TunnelProtocol { typealias TunnelManagerProtocol = SimulatorTunnelProviderManager - + var status: NEVPNStatus - + var isOnDemandEnabled: Bool - + var startDate: Date? - + required init(tunnelProvider: TunnelManagerProtocol) { status = .disconnected isOnDemandEnabled = false startDate = nil } - + // Observers are currently unimplemented func addObserver(_ observer: TunnelStatusObserver) {} - + func removeObserver(_ observer: TunnelStatusObserver) {} - - func addBlockObserver(queue: DispatchQueue?, handler: @escaping (any TunnelProtocol, NEVPNStatus) -> Void) -> TunnelStatusBlockObserver { + + func addBlockObserver( + queue: DispatchQueue?, + handler: @escaping (any TunnelProtocol, NEVPNStatus) -> Void + ) -> TunnelStatusBlockObserver { fatalError("MockTunnel.addBlockObserver Not implemented") } - + func logFormat() -> String { "" } - + func saveToPreferences(_ completion: @escaping (Error?) -> Void) { completion(nil) } - + func removeFromPreferences(completion: @escaping (Error?) -> Void) { completion(nil) } - + func setConfiguration(_ configuration: TunnelConfiguration) {} - - func start(options: [String : NSObject]?) throws { + + func start(options: [String: NSObject]?) throws { startDate = Date() } - + func stop() {} - + func sendProviderMessage(_ messageData: Data, responseHandler: ((Data?) -> Void)?) throws {} - - } diff --git a/ios/MullvadVPNTests/Mocks/MockTunnelInteractor.swift b/ios/MullvadVPNTests/Mocks/MockTunnelInteractor.swift index b9e2979e3a..49784143e8 100644 --- a/ios/MullvadVPNTests/Mocks/MockTunnelInteractor.swift +++ b/ios/MullvadVPNTests/Mocks/MockTunnelInteractor.swift @@ -10,19 +10,24 @@ import Foundation import MullvadSettings import PacketTunnelCore -// this is still very minimal, and will be fleshed out as needed. +// this is still very minimal, and will be fleshed out as needed. class MockTunnelInteractor: TunnelInteractor { var isConfigurationLoaded: Bool - + var settings: MullvadSettings.LatestTunnelSettings - + var deviceState: MullvadSettings.DeviceState - - var onUpdateTunnelStatus: ((TunnelStatus)->Void)? - + + var onUpdateTunnelStatus: ((TunnelStatus) -> Void)? + var tunnel: (any TunnelProtocol)? - - init(isConfigurationLoaded: Bool, settings: MullvadSettings.LatestTunnelSettings, deviceState: MullvadSettings.DeviceState, onUpdateTunnelStatus: ( (TunnelStatus) -> Void)? = nil) { + + init( + isConfigurationLoaded: Bool, + settings: MullvadSettings.LatestTunnelSettings, + deviceState: MullvadSettings.DeviceState, + onUpdateTunnelStatus: ((TunnelStatus) -> Void)? = nil + ) { self.isConfigurationLoaded = isConfigurationLoaded self.settings = settings self.deviceState = deviceState @@ -30,46 +35,44 @@ class MockTunnelInteractor: TunnelInteractor { self.tunnel = nil self.tunnelStatus = TunnelStatus() } - + func getPersistentTunnels() -> [any TunnelProtocol] { return [] } - + func createNewTunnel() -> any TunnelProtocol { return MockTunnel(tunnelProvider: SimulatorTunnelProviderManager()) } - + func setTunnel(_ tunnel: (any TunnelProtocol)?, shouldRefreshTunnelState: Bool) { self.tunnel = tunnel } - + var tunnelStatus: TunnelStatus - + func updateTunnelStatus(_ block: (inout TunnelStatus) -> Void) -> TunnelStatus { var tunnelStatus = self.tunnelStatus block(&tunnelStatus) onUpdateTunnelStatus?(tunnelStatus) return tunnelStatus } - + func setConfigurationLoaded() {} - - func setSettings(_ settings: MullvadSettings.LatestTunnelSettings, persist: Bool) { - } - - func setDeviceState(_ deviceState: MullvadSettings.DeviceState, persist: Bool) { - } - + + func setSettings(_ settings: MullvadSettings.LatestTunnelSettings, persist: Bool) {} + + func setDeviceState(_ deviceState: MullvadSettings.DeviceState, persist: Bool) {} + func removeLastUsedAccount() {} - + func handleRestError(_ error: Error) {} - + func startTunnel() {} - + func prepareForVPNConfigurationDeletion() {} - - struct NotImplementedError: Error { } - + + struct NotImplementedError: Error {} + func selectRelay() throws -> PacketTunnelCore.SelectedRelay { throw NotImplementedError() } diff --git a/ios/MullvadVPNTests/StartTunnelOperationTests.swift b/ios/MullvadVPNTests/StartTunnelOperationTests.swift index e6797649dc..840a88c6c5 100644 --- a/ios/MullvadVPNTests/StartTunnelOperationTests.swift +++ b/ios/MullvadVPNTests/StartTunnelOperationTests.swift @@ -6,20 +6,18 @@ // Copyright © 2024 Mullvad VPN AB. All rights reserved. // -import XCTest import MullvadSettings -import Operations import Network +import Operations import WireGuardKitTypes - +import XCTest class StartTunnelOperationTests: XCTestCase { - - //MARK: utility code for setting up tests - + // MARK: utility code for setting up tests + let testQueue = DispatchQueue(label: "StartTunnelOperationTests.testQueue") let operationQueue = AsyncOperationQueue() - + let loggedInDeviceState = DeviceState.loggedIn( StoredAccountData( identifier: "", @@ -36,7 +34,7 @@ class StartTunnelOperationTests: XCTestCase { wgKeyData: StoredWgKeyData(creationDate: Date(), privateKey: PrivateKey()) ) ) - + func makeInteractor(deviceState: DeviceState, tunnelState: TunnelState? = nil) -> MockTunnelInteractor { var interactor = MockTunnelInteractor( isConfigurationLoaded: true, @@ -48,54 +46,57 @@ class StartTunnelOperationTests: XCTestCase { } return interactor } - - //MARK: the tests + + // MARK: the tests func testFailsIfNotLoggedIn() throws { let settings = LatestTunnelSettings() - let exp = expectation(description:"Start tunnel operation failed") + let exp = expectation(description: "Start tunnel operation failed") let operation = StartTunnelOperation( dispatchQueue: testQueue, - interactor: makeInteractor(deviceState: .loggedOut)) { result in - guard case .failure(_) = result else { - XCTFail("Operation returned \(result), not failure") - return - } - exp.fulfill() + interactor: makeInteractor(deviceState: .loggedOut) + ) { result in + guard case .failure = result else { + XCTFail("Operation returned \(result), not failure") + return } - + exp.fulfill() + } + operationQueue.addOperation(operation) wait(for: [exp], timeout: 1.0) } - + func testSetsReconnectIfDisconnecting() { let settings = LatestTunnelSettings() var interactor = makeInteractor(deviceState: loggedInDeviceState, tunnelState: .disconnecting(.nothing)) var tunnelStatus = TunnelStatus() interactor.onUpdateTunnelStatus = { status in tunnelStatus = status } - let expectation = expectation(description:"Tunnel status set to reconnect") + let expectation = expectation(description: "Tunnel status set to reconnect") let operation = StartTunnelOperation( dispatchQueue: testQueue, - interactor: interactor) { result in - XCTAssertEqual(tunnelStatus.state, .disconnecting(.reconnect)) - expectation.fulfill() - } + interactor: interactor + ) { result in + XCTAssertEqual(tunnelStatus.state, .disconnecting(.reconnect)) + expectation.fulfill() + } operationQueue.addOperation(operation) wait(for: [expectation], timeout: 1.0) } - + func testStartsTunnelIfDisconnected() { let settings = LatestTunnelSettings() var interactor = makeInteractor(deviceState: loggedInDeviceState, tunnelState: .disconnected) - let expectation = expectation(description:"Make tunnel provider and start tunnel") + let expectation = expectation(description: "Make tunnel provider and start tunnel") let operation = StartTunnelOperation( dispatchQueue: testQueue, - interactor: interactor) { result in - XCTAssertNotNil(interactor.tunnel) - XCTAssertNotNil(interactor.tunnel?.startDate) - expectation.fulfill() - } + interactor: interactor + ) { result in + XCTAssertNotNil(interactor.tunnel) + XCTAssertNotNil(interactor.tunnel?.startDate) + expectation.fulfill() + } operationQueue.addOperation(operation) wait(for: [expectation], timeout: 1.0) } diff --git a/ios/Shared/ApplicationTarget.swift b/ios/Shared/ApplicationTarget.swift index c1f3224c58..98b0c97917 100644 --- a/ios/Shared/ApplicationTarget.swift +++ b/ios/Shared/ApplicationTarget.swift @@ -14,7 +14,8 @@ enum ApplicationTarget: CaseIterable { /// Returns target bundle identifier. var bundleIdentifier: String { // "MainApplicationIdentifier" does not exist if running tests - let mainBundleIdentifier = Bundle.main.object(forInfoDictionaryKey: "MainApplicationIdentifier") as? String ?? "tests" + let mainBundleIdentifier = Bundle.main + .object(forInfoDictionaryKey: "MainApplicationIdentifier") as? String ?? "tests" switch self { case .mainApp: return mainBundleIdentifier |
