Skip to content

Commit 4bc83d9

Browse files
committed
fix unix tests
1 parent 0d9a8e2 commit 4bc83d9

File tree

7 files changed

+111
-165
lines changed

7 files changed

+111
-165
lines changed

src/client/options/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,20 +1610,24 @@ impl ConnectionString {
16101610
None => (None, None),
16111611
};
16121612

1613-
let host_list = hosts_section.split(',');
1613+
let mut host_list = Vec::with_capacity(hosts_section.len());
16141614
// checks if the usage of uds is correct
1615-
host_list.clone().try_for_each(|host| {
1615+
for host in hosts_section.split(',') {
16161616
if host.ends_with(".sock") {
16171617
#[cfg(unix)]
1618-
percent_decode(host, "Unix domain sockets must be URL-encoded")?;
1618+
host_list.push(percent_decode(
1619+
host,
1620+
"Unix domain sockets must be URL-encoded",
1621+
)?);
16191622
#[cfg(not(unix))]
16201623
return Err(ErrorKind::InvalidArgument {
16211624
message: "Unix domain sockets are not supported on this platform".into(),
16221625
});
1626+
} else {
1627+
host_list.push(host.to_string());
16231628
}
1624-
Ok::<(), crate::error::Error>(())
1625-
})?;
1626-
let host_list: Result<Vec<_>> = host_list.map(ServerAddress::parse).collect();
1629+
}
1630+
let host_list: Result<Vec<_>> = host_list.into_iter().map(ServerAddress::parse).collect();
16271631

16281632
let host_list = host_list?;
16291633

src/client/options/test.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async fn run_test(test_file: TestFile) {
4343
|| test_case.description.contains("tlsAllowInvalidHostnames")
4444
|| test_case.description.contains("single-threaded")
4545
|| test_case.description.contains("serverSelectionTryOnce")
46-
|| test_case.description.contains("Unix")
4746
|| test_case.description.contains("relative path")
4847
// Compression is implemented but will only pass the tests if all
4948
// the appropriate feature flags are set. That is because
@@ -63,19 +62,37 @@ async fn run_test(test_file: TestFile) {
6362
continue;
6463
}
6564

65+
#[cfg(not(unix))]
66+
if test_case.description.contains("Unix") {
67+
continue;
68+
}
69+
6670
let warning = test_case.warning.take().unwrap_or(false);
6771

6872
if test_case.valid && !warning {
6973
let mut is_unsupported_host_type = false;
7074
// hosts
7175
if let Some(mut json_hosts) = test_case.hosts.take() {
7276
// skip over unsupported host types
73-
is_unsupported_host_type = json_hosts.iter_mut().any(|h_json| {
74-
matches!(
75-
h_json.remove("type").as_ref().and_then(Bson::as_str),
76-
Some("ip_literal") | Some("unix")
77-
)
78-
});
77+
#[cfg(not(unix))]
78+
{
79+
is_unsupported_host_type = json_hosts.iter_mut().any(|h_json| {
80+
matches!(
81+
h_json.remove("type").as_ref().and_then(Bson::as_str),
82+
Some("ip_literal") | Some("unix")
83+
)
84+
});
85+
}
86+
87+
#[cfg(unix)]
88+
{
89+
is_unsupported_host_type = json_hosts.iter_mut().any(|h_json| {
90+
matches!(
91+
h_json.remove("type").as_ref().and_then(Bson::as_str),
92+
Some("ip_literal")
93+
)
94+
});
95+
}
7996

8097
if !is_unsupported_host_type {
8198
let options = ClientOptions::parse(&test_case.uri).await.unwrap();

src/test/spec/json/connection-string/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ array of test case objects, each of which have the following keys:
3333

3434
- ``type``: A string denoting the type of host. Possible values are "ipv4",
3535
"ip_literal", "hostname", and "unix". Asserting the type is *optional*.
36+
- ``path``: A string representing the path of unix domain socket.
3637
- ``host``: A string containing the parsed host.
3738
- ``port``: An integer containing the parsed port number.
3839
- ``auth``: An object containing the following keys:

src/test/spec/json/connection-string/valid-unix_socket-absolute.json

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"hosts": [
99
{
1010
"type": "unix",
11-
"host": "/tmp/mongodb-27017.sock",
12-
"port": null
11+
"path": "/tmp/mongodb-27017.sock"
1312
}
1413
],
1514
"auth": null,
@@ -23,8 +22,7 @@
2322
"hosts": [
2423
{
2524
"type": "unix",
26-
"host": "/tmp/mongodb-27017.sock",
27-
"port": null
25+
"path": "/tmp/mongodb-27017.sock"
2826
}
2927
],
3028
"auth": null,
@@ -38,8 +36,7 @@
3836
"hosts": [
3937
{
4038
"type": "unix",
41-
"host": "/tmp/ /mongodb-27017.sock",
42-
"port": null
39+
"path": "/tmp/ /mongodb-27017.sock"
4340
}
4441
],
4542
"auth": null,
@@ -53,13 +50,11 @@
5350
"hosts": [
5451
{
5552
"type": "unix",
56-
"host": "/tmp/mongodb-27017.sock",
57-
"port": null
53+
"path": "/tmp/mongodb-27017.sock"
5854
},
5955
{
6056
"type": "unix",
61-
"host": "/tmp/mongodb-27018.sock",
62-
"port": null
57+
"path": "/tmp/mongodb-27018.sock"
6358
}
6459
],
6560
"auth": null,
@@ -78,8 +73,7 @@
7873
},
7974
{
8075
"type": "unix",
81-
"host": "/tmp/mongodb-27017.sock",
82-
"port": null
76+
"path": "/tmp/mongodb-27017.sock"
8377
}
8478
],
8579
"auth": null,
@@ -93,13 +87,11 @@
9387
"hosts": [
9488
{
9589
"type": "hostname",
96-
"host": "mongodb-27017.sock",
97-
"port": null
90+
"path": "mongodb-27017.sock"
9891
},
9992
{
10093
"type": "unix",
101-
"host": "/tmp/mongodb-27018.sock",
102-
"port": null
94+
"path": "/tmp/mongodb-27018.sock"
10395
}
10496
],
10597
"auth": null,
@@ -113,8 +105,7 @@
113105
"hosts": [
114106
{
115107
"type": "unix",
116-
"host": "/tmp/mongodb-27017.sock",
117-
"port": null
108+
"path": "/tmp/mongodb-27017.sock"
118109
}
119110
],
120111
"auth": {
@@ -132,8 +123,7 @@
132123
"hosts": [
133124
{
134125
"type": "unix",
135-
"host": "/tmp/path.to.sock/mongodb-27017.sock",
136-
"port": null
126+
"path": "/tmp/path.to.sock/mongodb-27017.sock"
137127
}
138128
],
139129
"auth": null,
@@ -147,8 +137,7 @@
147137
"hosts": [
148138
{
149139
"type": "unix",
150-
"host": "/tmp/path.to.sock/mongodb-27017.sock",
151-
"port": null
140+
"path": "/tmp/path.to.sock/mongodb-27017.sock"
152141
}
153142
],
154143
"auth": null,
@@ -162,8 +151,7 @@
162151
"hosts": [
163152
{
164153
"type": "unix",
165-
"host": "/tmp/path.to.sock/mongodb-27017.sock",
166-
"port": null
154+
"path": "/tmp/path.to.sock/mongodb-27017.sock"
167155
}
168156
],
169157
"auth": {
@@ -181,13 +169,11 @@
181169
"hosts": [
182170
{
183171
"type": "unix",
184-
"host": "/tmp/mongodb-27017.sock",
185-
"port": null
172+
"path": "/tmp/mongodb-27017.sock"
186173
},
187174
{
188175
"type": "unix",
189-
"host": "/tmp/mongodb-27018.sock",
190-
"port": null
176+
"path": "/tmp/mongodb-27018.sock"
191177
}
192178
],
193179
"auth": {
@@ -205,13 +191,11 @@
205191
"hosts": [
206192
{
207193
"type": "unix",
208-
"host": "/tmp/mongodb-27017.sock",
209-
"port": null
194+
"path": "/tmp/mongodb-27017.sock"
210195
},
211196
{
212197
"type": "unix",
213-
"host": "/tmp/mongodb-27018.sock",
214-
"port": null
198+
"path": "/tmp/mongodb-27018.sock"
215199
}
216200
],
217201
"auth": {
@@ -229,13 +213,11 @@
229213
"hosts": [
230214
{
231215
"type": "unix",
232-
"host": "/tmp/mongodb-27017.sock",
233-
"port": null
216+
"path": "/tmp/mongodb-27017.sock"
234217
},
235218
{
236219
"type": "unix",
237-
"host": "/tmp/mongodb-27018.sock",
238-
"port": null
220+
"path": "/tmp/mongodb-27018.sock"
239221
}
240222
],
241223
"auth": {

0 commit comments

Comments
 (0)