@@ -18,7 +18,9 @@ class RelaySelectorTests: XCTestCase {
18
18
let sampleRelays = ServerRelaysResponseStubs . sampleRelays
19
19
20
20
func testCountryConstraint( ) throws {
21
- let constraints = RelayConstraints ( location: . only( . country( " es " ) ) )
21
+ let constraints = RelayConstraints (
22
+ locations: . only( RelayLocations ( locations: [ . country( " es " ) ] ) )
23
+ )
22
24
23
25
let result = try RelaySelector . evaluate (
24
26
relays: sampleRelays,
@@ -30,7 +32,10 @@ class RelaySelectorTests: XCTestCase {
30
32
}
31
33
32
34
func testCityConstraint( ) throws {
33
- let constraints = RelayConstraints ( location: . only( . city( " se " , " got " ) ) )
35
+ let constraints = RelayConstraints (
36
+ locations: . only( RelayLocations ( locations: [ . city( " se " , " got " ) ] ) )
37
+ )
38
+
34
39
let result = try RelaySelector . evaluate (
35
40
relays: sampleRelays,
36
41
constraints: constraints,
@@ -41,7 +46,9 @@ class RelaySelectorTests: XCTestCase {
41
46
}
42
47
43
48
func testHostnameConstraint( ) throws {
44
- let constraints = RelayConstraints ( location: . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) )
49
+ let constraints = RelayConstraints (
50
+ locations: . only( RelayLocations ( locations: [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) )
51
+ )
45
52
46
53
let result = try RelaySelector . evaluate (
47
54
relays: sampleRelays,
@@ -53,7 +60,10 @@ class RelaySelectorTests: XCTestCase {
53
60
}
54
61
55
62
func testSpecificPortConstraint( ) throws {
56
- let constraints = RelayConstraints ( location: . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) , port: . only( 1 ) )
63
+ let constraints = RelayConstraints (
64
+ locations: . only( RelayLocations ( locations: [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) ) ,
65
+ port: . only( 1 )
66
+ )
57
67
58
68
let result = try RelaySelector . evaluate (
59
69
relays: sampleRelays,
@@ -65,7 +75,9 @@ class RelaySelectorTests: XCTestCase {
65
75
}
66
76
67
77
func testRandomPortSelectionWithFailedAttempts( ) throws {
68
- let constraints = RelayConstraints ( location: . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) )
78
+ let constraints = RelayConstraints (
79
+ locations: . only( RelayLocations ( locations: [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) )
80
+ )
69
81
let allPorts = portRanges. flatMap { $0 }
70
82
71
83
var result = try RelaySelector . evaluate (
@@ -89,15 +101,19 @@ class RelaySelectorTests: XCTestCase {
89
101
}
90
102
91
103
func testClosestShadowsocksRelay( ) throws {
92
- let constraints = RelayConstraints ( location: . only( . city( " se " , " sto " ) ) )
104
+ let constraints = RelayConstraints (
105
+ locations: . only( RelayLocations ( locations: [ . city( " se " , " sto " ) ] ) )
106
+ )
93
107
94
108
let selectedRelay = RelaySelector . closestShadowsocksRelayConstrained ( by: constraints, in: sampleRelays)
95
109
96
110
XCTAssertEqual ( selectedRelay? . hostname, " se-sto-br-001 " )
97
111
}
98
112
99
113
func testClosestShadowsocksRelayIsRandomWhenNoContraintsAreSatisfied( ) throws {
100
- let constraints = RelayConstraints ( location: . only( . country( " INVALID COUNTRY " ) ) )
114
+ let constraints = RelayConstraints (
115
+ locations: . only( RelayLocations ( locations: [ . country( " INVALID COUNTRY " ) ] ) )
116
+ )
101
117
102
118
let selectedRelay = try XCTUnwrap ( RelaySelector . closestShadowsocksRelayConstrained (
103
119
by: constraints,
@@ -109,8 +125,9 @@ class RelaySelectorTests: XCTestCase {
109
125
110
126
func testRelayFilterConstraintWithOwnedOwnership( ) throws {
111
127
let filter = RelayFilter ( ownership: . owned, providers: . any)
128
+
112
129
let constraints = RelayConstraints (
113
- location : . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) ,
130
+ locations : . only( RelayLocations ( locations : [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) ) ,
114
131
filter: . only( filter)
115
132
)
116
133
@@ -125,8 +142,9 @@ class RelaySelectorTests: XCTestCase {
125
142
126
143
func testRelayFilterConstraintWithRentedOwnership( ) throws {
127
144
let filter = RelayFilter ( ownership: . rented, providers: . any)
145
+
128
146
let constraints = RelayConstraints (
129
- location : . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) ,
147
+ locations : . only( RelayLocations ( locations : [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) ) ,
130
148
filter: . only( filter)
131
149
)
132
150
@@ -141,10 +159,10 @@ class RelaySelectorTests: XCTestCase {
141
159
142
160
func testRelayFilterConstraintWithCorrectProvider( ) throws {
143
161
let provider = " 31173 "
144
-
145
162
let filter = RelayFilter ( ownership: . any, providers: . only( [ provider] ) )
163
+
146
164
let constraints = RelayConstraints (
147
- location : . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) ,
165
+ locations : . only( RelayLocations ( locations : [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) ) ,
148
166
filter: . only( filter)
149
167
)
150
168
@@ -159,10 +177,10 @@ class RelaySelectorTests: XCTestCase {
159
177
160
178
func testRelayFilterConstraintWithIncorrectProvider( ) throws {
161
179
let provider = " DataPacket "
162
-
163
180
let filter = RelayFilter ( ownership: . any, providers: . only( [ provider] ) )
181
+
164
182
let constraints = RelayConstraints (
165
- location : . only( . hostname( " se " , " sto " , " se6-wireguard " ) ) ,
183
+ locations : . only( RelayLocations ( locations : [ . hostname( " se " , " sto " , " se6-wireguard " ) ] ) ) ,
166
184
filter: . only( filter)
167
185
)
168
186
0 commit comments