-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathTunnelStore+Stubs.swift
75 lines (55 loc) · 2.01 KB
/
TunnelStore+Stubs.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
//
// TunnelStore+Stubs.swift
// MullvadVPNTests
//
// Created by Marco Nikic on 2023-10-03.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import Foundation
@testable import MullvadVPN
import NetworkExtension
struct TunnelStoreStub: TunnelStoreProtocol {
typealias TunnelType = TunnelStub
func getPersistentTunnels() -> [TunnelType] {
[]
}
func createNewTunnel() -> TunnelType {
TunnelStub(status: .invalid, isOnDemandEnabled: false)
}
}
class DummyTunnelStatusObserver: TunnelStatusObserver {
func tunnel(_ tunnel: any TunnelProtocol, didReceiveStatus status: NEVPNStatus) {}
}
final class TunnelStub: TunnelProtocol, Equatable {
convenience init(tunnelProvider: TunnelProviderManagerType) {
self.init(status: .invalid, isOnDemandEnabled: false)
}
static func == (lhs: TunnelStub, rhs: TunnelStub) -> Bool {
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}
init(status: NEVPNStatus, isOnDemandEnabled: Bool, startDate: Date? = nil) {
self.status = status
self.isOnDemandEnabled = isOnDemandEnabled
self.startDate = startDate
}
func addObserver(_ observer: TunnelStatusObserver) {}
func removeObserver(_ observer: TunnelStatusObserver) {}
var status: NEVPNStatus
var isOnDemandEnabled: Bool
var startDate: Date?
func addBlockObserver(
queue: DispatchQueue?,
handler: @escaping (any TunnelProtocol, NEVPNStatus) -> Void
) -> TunnelStatusBlockObserver {
TunnelStatusBlockObserver(tunnel: self, queue: queue, handler: handler)
}
func logFormat() -> String {
""
}
func saveToPreferences(_ completion: @escaping (Error?) -> Void) {}
func removeFromPreferences(completion: @escaping (Error?) -> Void) {}
func setConfiguration(_ configuration: TunnelConfiguration) {}
func start(options: [String: NSObject]?) throws {}
func stop() {}
func sendProviderMessage(_ messageData: Data, responseHandler: ((Data?) -> Void)?) throws {}
}