diff options
| author | Andrew Bulhak <andrew.bulhak@mullvad.net> | 2024-02-02 12:06:58 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-02-07 15:13:22 +0100 |
| commit | 6a579a015f5ec8aff4b1550fb7c72d92aae492c3 (patch) | |
| tree | 45b41adaf76bba10ddce31630ff435bd01d40a18 | |
| parent | 1053b6347d16fa87ffebce1ec66734c8e7fae430 (diff) | |
| download | mullvadvpn-6a579a015f5ec8aff4b1550fb7c72d92aae492c3.tar.xz mullvadvpn-6a579a015f5ec8aff4b1550fb7c72d92aae492c3.zip | |
Add initial (nonbuilding) tests
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPNTests/StartTunnelOperationTests.swift | 103 |
2 files changed, 107 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 17c25c9e92..2b5da62ba8 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ 06799AFC28F98EE300ACD94E /* AddressCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AC114128F8413A0037AF9A /* AddressCache.swift */; }; 0697D6E728F01513007A9E99 /* TransportMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0697D6E628F01513007A9E99 /* TransportMonitor.swift */; }; 06AC116228F94C450037AF9A /* ApplicationConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */; }; + 44DD7D242B6CFFD70005F67F /* StartTunnelOperationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */; }; 5803B4B02940A47300C23744 /* TunnelConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5803B4AF2940A47300C23744 /* TunnelConfiguration.swift */; }; 5803B4B22940A48700C23744 /* TunnelStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5803B4B12940A48700C23744 /* TunnelStore.swift */; }; 5807E2C02432038B00F5FF30 /* String+Split.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5807E2BF2432038B00F5FF30 /* String+Split.swift */; }; @@ -1238,6 +1239,7 @@ 06FAE67A28F83CA50033DD93 /* RESTDevicesProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTDevicesProxy.swift; sourceTree = "<group>"; }; 06FAE67B28F83CA50033DD93 /* REST.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = REST.swift; sourceTree = "<group>"; }; 06FAE67D28F83CA50033DD93 /* RESTTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTTransport.swift; sourceTree = "<group>"; }; + 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartTunnelOperationTests.swift; sourceTree = "<group>"; }; 5802EBC42A8E44AC00E5CE4C /* AppRoutes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRoutes.swift; sourceTree = "<group>"; }; 5802EBC62A8E457A00E5CE4C /* AppRouteProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRouteProtocol.swift; sourceTree = "<group>"; }; 5802EBC82A8E45BA00E5CE4C /* ApplicationRouterDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationRouterDelegate.swift; sourceTree = "<group>"; }; @@ -2774,6 +2776,7 @@ F09D04BA2AE95396003D4F89 /* URLSessionStub.swift */, 58165EBD2A262CBB00688EAD /* WgKeyRotationTests.swift */, F0B0E6962AFE6E7E001DC66B /* XCTest+Async.swift */, + 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */, ); path = MullvadVPNTests; sourceTree = "<group>"; @@ -4632,6 +4635,7 @@ A9A5FA292ACB05160083449F /* AddressCacheTests.swift in Sources */, A9B6AC182ADE8F4300F7802A /* MigrationManagerTests.swift in Sources */, A9A5FA2A2ACB05160083449F /* CoordinatesTests.swift in Sources */, + 44DD7D242B6CFFD70005F67F /* StartTunnelOperationTests.swift in Sources */, A9A5FA2B2ACB05160083449F /* CustomDateComponentsFormattingTests.swift in Sources */, A9A5FA2C2ACB05160083449F /* DeviceCheckOperationTests.swift in Sources */, A9A5FA2D2ACB05160083449F /* DurationTests.swift in Sources */, diff --git a/ios/MullvadVPNTests/StartTunnelOperationTests.swift b/ios/MullvadVPNTests/StartTunnelOperationTests.swift new file mode 100644 index 0000000000..31d32b3310 --- /dev/null +++ b/ios/MullvadVPNTests/StartTunnelOperationTests.swift @@ -0,0 +1,103 @@ +// +// StartTunnelOperationTests.swift +// MullvadVPNTests +// +// Created by Andrew Bulhak on 2024-02-02. +// Copyright © 2024 Mullvad VPN AB. All rights reserved. +// + +import XCTest +import MullvadSettings +import Operations +import PacketTunnelCore + +struct MockTunnelInteractor: TunnelInteractor { + var tunnel: (TunnelProtocol)? + + func getPersistentTunnels() -> [TunnelProtocol] { + return [] + } + + func createNewTunnel() -> TunnelProtocol { + fatalError() + } + + func setTunnel(_ tunnel: (TunnelProtocol)?, shouldRefreshTunnelState: Bool) { + + } + + var tunnelStatus: TunnelStatus { + TunnelStatus() + } + + func updateTunnelStatus(_ block: (inout TunnelStatus) -> Void) -> TunnelStatus { + TunnelStatus() + } + + var isConfigurationLoaded: Bool + + var settings: MullvadSettings.LatestTunnelSettings + + var deviceState: MullvadSettings.DeviceState + + func setConfigurationLoaded() { + } + + func setSettings(_ settings: MullvadSettings.LatestTunnelSettings, persist: Bool) { + } + + func setDeviceState(_ deviceState: MullvadSettings.DeviceState, persist: Bool) { + } + + func removeLastUsedAccount() { + } + + func handleRestError(_ error: Error) { + } + + func startTunnel() { + } + + func prepareForVPNConfigurationDeletion() { + } + + func selectRelay() throws -> PacketTunnelCore.SelectedRelay { + fatalError() + } + + +} + +final class StartTunnelOperationTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testFailsIfNotLoggedIn() throws { + let operationQueue = AsyncOperationQueue() + let testQueue = DispatchQueue(label: "StartTunnelOperationTests.testQueue") + let settings = LatestTunnelSettings() + let expectation = XCTestExpectation(description:"") + let operation = StartTunnelOperation( + dispatchQueue: testQueue, + interactor: MockTunnelInteractor(isConfigurationLoaded: true, settings: settings, deviceState: .loggedOut)) { result in + + guard case let .failure(err) = result else { + XCTFail("Operation returned \(result), not failure") + return + } + + expectation.fulfill() + + } + + operationQueue.addOperation(operation) + wait(for: [expectation], timeout: 10.0) + } + +} |
