-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathStartTunnelOperationTests.swift
103 lines (73 loc) · 2.7 KB
/
StartTunnelOperationTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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)
}
}