summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnelCoreTests/Mocks/DefaultPathObserverFake.swift
blob: c80001b506b63f43bb7c84e776d9d590cc5de56d (plain)
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
//
//  DefaultPathObserverFake.swift
//  PacketTunnelCoreTests
//
//  Created by pronebird on 16/08/2023.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import Network
import NetworkExtension
import PacketTunnelCore

/// Default path observer fake that uses in-memory storage to keep current path and provides a method to simulate path change from tests.
class DefaultPathObserverFake: DefaultPathObserverProtocol, @unchecked Sendable {
    var currentPathStatus: Network.NWPath.Status { .satisfied }
    private var defaultPathHandler: ((Network.NWPath.Status) -> Void)?

    public var onStart: (() -> Void)?
    public var onStop: (() -> Void)?

    func start(_ body: @escaping (Network.NWPath.Status) -> Void) {
        defaultPathHandler = body
        onStart?()
    }

    func stop() {
        defaultPathHandler = nil
        onStop?()
    }

    /// Simulate network path update.
    func updatePath(_ newPath: Network.NWPath.Status) {}
}