Skip to content

Commit bf6115e

Browse files
committed
Fix Error compares in tests
1 parent 2c156ff commit bf6115e

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{fmt::Formatter, io, net::SocketAddrV6, string::FromUtf8Error};
22

33
/// Errors from socks2
4+
///
5+
/// # Notes
6+
/// `Error` implements PartialEq, but it does not compare fields.
47
#[derive(Debug)]
58
#[non_exhaustive]
69
#[allow(missing_docs)]

src/v4.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,14 @@ pub mod bind {
247247
#[cfg(test)]
248248
#[allow(clippy::unwrap_used)]
249249
mod test {
250-
use std::{
251-
io::{Read, Write},
252-
net::{SocketAddr, SocketAddrV4, TcpStream, ToSocketAddrs},
253-
};
254-
255250
#[cfg(feature = "bind")]
256251
use super::bind::*;
257252
#[cfg(feature = "client")]
258253
use super::client::*;
254+
use std::{
255+
io::{Read, Write},
256+
net::{SocketAddr, SocketAddrV4, TcpStream, ToSocketAddrs},
257+
};
259258

260259
const PROXY_ADDR: &str = "127.0.0.1:1084";
261260

src/v5.rs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,18 @@ pub mod udp {
580580
#[cfg(test)]
581581
#[allow(clippy::unwrap_used)]
582582
mod test {
583-
use std::{
584-
io::{Read, Write},
585-
net::{TcpStream, ToSocketAddrs, UdpSocket},
586-
};
587-
588583
#[cfg(feature = "bind")]
589584
use super::bind::*;
590585
#[cfg(feature = "client")]
591586
use super::client::*;
592587
#[cfg(feature = "udp")]
593588
use super::udp::*;
594589
use super::*;
590+
use crate::unwrap_io_to_socks2_error;
591+
use std::{
592+
io::{Read, Write},
593+
net::{TcpStream, ToSocketAddrs, UdpSocket},
594+
};
595595

596596
const SOCKS_PROXY_NO_AUTH_ONLY: &str = "127.0.0.1:1084";
597597
const SOCKS_PROXY_PASSWD_ONLY: &str = "127.0.0.1:1085";
@@ -780,8 +780,10 @@ mod test {
780780
let addr = "google.com:80".to_socket_addrs().unwrap().next().unwrap();
781781
let err = Socks5Stream::connect(SOCKS_PROXY_PASSWD_ONLY, &addr).unwrap_err();
782782

783-
assert_eq!(err.kind(), io::ErrorKind::Other);
784-
assert_eq!(err.to_string(), "no acceptable auth methods");
783+
assert_eq!(
784+
unwrap_io_to_socks2_error(&err),
785+
Some(&Error::NoAuthMethods { method: 99 })
786+
);
785787
}
786788

787789
#[test]
@@ -796,8 +798,10 @@ mod test {
796798
&string_of_size(1),
797799
)
798800
.unwrap_err();
799-
assert_eq!(err.kind(), io::ErrorKind::PermissionDenied);
800-
assert_eq!(err.to_string(), "password authentication failed");
801+
assert_eq!(
802+
unwrap_io_to_socks2_error(&err),
803+
Some(&Error::FailedPasswordAuth {})
804+
);
801805

802806
let err = Socks5Stream::connect_with_password(
803807
SOCKS_PROXY_PASSWD_ONLY,
@@ -806,8 +810,10 @@ mod test {
806810
&string_of_size(255),
807811
)
808812
.unwrap_err();
809-
assert_eq!(err.kind(), io::ErrorKind::PermissionDenied);
810-
assert_eq!(err.to_string(), "password authentication failed");
813+
assert_eq!(
814+
unwrap_io_to_socks2_error(&err),
815+
Some(&Error::FailedPasswordAuth {})
816+
);
811817

812818
let err = Socks5Stream::connect_with_password(
813819
SOCKS_PROXY_PASSWD_ONLY,
@@ -816,8 +822,13 @@ mod test {
816822
&string_of_size(255),
817823
)
818824
.unwrap_err();
819-
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
820-
assert_eq!(err.to_string(), "invalid username");
825+
assert_eq!(
826+
unwrap_io_to_socks2_error(&err),
827+
Some(&Error::InvalidUsername {
828+
username: "1".to_string(),
829+
length: 1
830+
})
831+
);
821832

822833
let err = Socks5Stream::connect_with_password(
823834
SOCKS_PROXY_PASSWD_ONLY,
@@ -826,8 +837,13 @@ mod test {
826837
&string_of_size(255),
827838
)
828839
.unwrap_err();
829-
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
830-
assert_eq!(err.to_string(), "invalid username");
840+
assert_eq!(
841+
unwrap_io_to_socks2_error(&err),
842+
Some(&Error::InvalidUsername {
843+
username: "1".to_string(),
844+
length: 1
845+
})
846+
);
831847

832848
let err = Socks5Stream::connect_with_password(
833849
SOCKS_PROXY_PASSWD_ONLY,
@@ -836,8 +852,13 @@ mod test {
836852
&string_of_size(0),
837853
)
838854
.unwrap_err();
839-
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
840-
assert_eq!(err.to_string(), "invalid password");
855+
assert_eq!(
856+
unwrap_io_to_socks2_error(&err),
857+
Some(&Error::InvalidPassword {
858+
password: (),
859+
length: 1
860+
})
861+
);
841862

842863
let err = Socks5Stream::connect_with_password(
843864
SOCKS_PROXY_PASSWD_ONLY,
@@ -846,8 +867,13 @@ mod test {
846867
&string_of_size(256),
847868
)
848869
.unwrap_err();
849-
assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
850-
assert_eq!(err.to_string(), "invalid password");
870+
assert_eq!(
871+
unwrap_io_to_socks2_error(&err),
872+
Some(&Error::InvalidPassword {
873+
password: (),
874+
length: 1
875+
})
876+
);
851877
}
852878

853879
#[cfg(feature = "client")]

0 commit comments

Comments
 (0)