Skip to content

Commit 2100f1c

Browse files
committed
Add test for filter
1 parent d0c92ab commit 2100f1c

24 files changed

+514
-156
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// MockRelayCache.swift
3+
// MullvadVPN
4+
//
5+
// Created by Mojgan on 2025-03-10.
6+
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
7+
//
8+
import Foundation
9+
@testable import MullvadREST
10+
11+
public struct MockRelayCache: RelayCacheProtocol {
12+
public init() {}
13+
14+
public func read() throws -> MullvadREST.StoredRelays {
15+
try .init(
16+
cachedRelays: CachedRelays(
17+
relays: ServerRelaysResponseStubs.sampleRelays,
18+
updatedAt: Date()
19+
)
20+
)
21+
}
22+
23+
public func readPrebundledRelays() throws -> MullvadREST.StoredRelays {
24+
try self.read()
25+
}
26+
27+
public func write(record: MullvadREST.StoredRelays) throws {}
28+
}

ios/MullvadMockData/MullvadREST/RelaySelectorStub.swift

+4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import WireGuardKitTypes
1313

1414
/// Relay selector stub that accepts a block that can be used to provide custom implementation.
1515
public final class RelaySelectorStub: RelaySelectorProtocol {
16+
public let relayCache: any RelayCacheProtocol
17+
1618
var selectedRelaysResult: (UInt) throws -> SelectedRelays
1719
var candidatesResult: (() throws -> RelayCandidates)?
1820

1921
init(
22+
relayCache: RelayCacheProtocol = MockRelayCache(),
2023
selectedRelaysResult: @escaping (UInt) throws -> SelectedRelays,
2124
candidatesResult: (() throws -> RelayCandidates)? = nil
2225
) {
26+
self.relayCache = relayCache
2327
self.selectedRelaysResult = selectedRelaysResult
2428
self.candidatesResult = candidatesResult
2529
}

ios/MullvadVPNTests/MullvadREST/ApiHandlers/ServerRelaysResponse+Stubs.swift ios/MullvadMockData/MullvadREST/ServerRelaysResponse+Stubs.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import Foundation
1010
@testable import MullvadREST
1111
import WireGuardKitTypes
1212

13-
enum ServerRelaysResponseStubs {
14-
static let wireguardPortRanges: [[UInt16]] = [[4000, 4001], [5000, 5001]]
15-
static let shadowsocksPortRanges: [[UInt16]] = [[51900, 51949]]
13+
public enum ServerRelaysResponseStubs {
14+
public static let wireguardPortRanges: [[UInt16]] = [[4000, 4001], [5000, 5001]]
15+
public static let shadowsocksPortRanges: [[UInt16]] = [[51900, 51949]]
1616

17-
static let sampleRelays = REST.ServerRelaysResponse(
17+
public static let sampleRelays = REST.ServerRelaysResponse(
1818
locations: [
1919
"es-mad": REST.ServerLocation(
2020
country: "Spain",
@@ -79,9 +79,9 @@ enum ServerRelaysResponseStubs {
7979
REST.ServerRelay(
8080
hostname: "es1-wireguard",
8181
active: true,
82-
owned: true,
82+
owned: false,
8383
location: "es-mad",
84-
provider: "",
84+
provider: "100TB",
8585
weight: 500,
8686
ipv4AddrIn: .loopback,
8787
ipv6AddrIn: .loopback,
@@ -95,7 +95,7 @@ enum ServerRelaysResponseStubs {
9595
active: true,
9696
owned: true,
9797
location: "se-got",
98-
provider: "",
98+
provider: "Blix",
9999
weight: 1000,
100100
ipv4AddrIn: .loopback,
101101
ipv6AddrIn: .loopback,
@@ -109,7 +109,7 @@ enum ServerRelaysResponseStubs {
109109
active: true,
110110
owned: true,
111111
location: "se-sto",
112-
provider: "",
112+
provider: "DataPacket",
113113
weight: 50,
114114
ipv4AddrIn: .loopback,
115115
ipv6AddrIn: .loopback,
@@ -137,7 +137,7 @@ enum ServerRelaysResponseStubs {
137137
active: true,
138138
owned: true,
139139
location: "us-dal",
140-
provider: "",
140+
provider: "M247",
141141
weight: 100,
142142
ipv4AddrIn: .loopback,
143143
ipv6AddrIn: .loopback,
@@ -149,9 +149,9 @@ enum ServerRelaysResponseStubs {
149149
REST.ServerRelay(
150150
hostname: "us-nyc-wg-301",
151151
active: true,
152-
owned: true,
152+
owned: false,
153153
location: "us-nyc",
154-
provider: "",
154+
provider: "xtom",
155155
weight: 100,
156156
ipv4AddrIn: .loopback,
157157
ipv6AddrIn: .loopback,
@@ -165,7 +165,7 @@ enum ServerRelaysResponseStubs {
165165
active: false,
166166
owned: true,
167167
location: "us-nyc",
168-
provider: "",
168+
provider: "Qnax",
169169
weight: 100,
170170
ipv4AddrIn: .loopback,
171171
ipv6AddrIn: .loopback,

ios/MullvadREST/Relay/RelayCandidates.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
77
//
88

9-
public struct RelayCandidates: Equatable {
9+
public struct RelayCandidates: Equatable, Sendable {
1010
public let entryRelays: [RelayWithLocation<REST.ServerRelay>]?
1111
public let exitRelays: [RelayWithLocation<REST.ServerRelay>]
1212
public init(

ios/MullvadREST/Relay/RelaySelectorProtocol.swift

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import MullvadTypes
1212

1313
/// Protocol describing a type that can select a relay.
1414
public protocol RelaySelectorProtocol {
15+
var relayCache: RelayCacheProtocol { get }
1516
func selectRelays(
1617
tunnelSettings: LatestTunnelSettings,
1718
connectionAttemptCount: UInt

ios/MullvadREST/Relay/RelayWithLocation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010
import MullvadTypes
1111

12-
public struct RelayWithLocation<T: AnyRelay> {
12+
public struct RelayWithLocation<T: AnyRelay & Sendable>: Sendable {
1313
public let relay: T
1414
public let serverLocation: Location
1515

0 commit comments

Comments
 (0)