Skip to content

Commit 29b04ca

Browse files
committed
varlink-certification: remove unnecessary alloc
Remove unnecessary String allocation in varlink-certification tests Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
1 parent 6293580 commit 29b04ca

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

varlink-certification/src/test.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ use varlink::Connection;
44

55
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
66

7-
fn run_self_test(address: String) -> Result<()> {
8-
let client_address = address.clone();
9-
7+
fn run_self_test(address: &'static str) -> Result<()> {
108
let child = thread::spawn(move || {
11-
if let Err(e) = crate::run_server(&address, 4) {
9+
if let Err(e) = crate::run_server(address, 4) {
1210
match e.kind() {
1311
::varlink::ErrorKind::Timeout => {}
1412
_ => panic!("error: {:#?}", e),
@@ -19,7 +17,7 @@ fn run_self_test(address: String) -> Result<()> {
1917
// give server time to start
2018
thread::sleep(time::Duration::from_secs(1));
2119

22-
let ret = crate::run_client(Connection::with_address(&client_address)?);
20+
let ret = crate::run_client(Connection::with_address(address)?);
2321
if let Err(e) = ret {
2422
panic!("error: {:?}", e);
2523
}
@@ -32,21 +30,21 @@ fn run_self_test(address: String) -> Result<()> {
3230

3331
#[test]
3432
fn test_unix() -> crate::Result<()> {
35-
run_self_test("unix:org.varlink.certification".into())
33+
run_self_test("unix:org.varlink.certification")
3634
}
3735

3836
#[test]
3937
#[cfg(any(target_os = "linux", target_os = "android"))]
4038
fn test_unix_abstract() -> Result<()> {
41-
run_self_test("unix:@org.varlink.certification_abs".into())
39+
run_self_test("unix:@org.varlink.certification_abs")
4240
}
4341

4442
#[test]
4543
fn test_tcp() -> Result<()> {
46-
run_self_test("tcp:127.0.0.1:23456".into())
44+
run_self_test("tcp:127.0.0.1:23456")
4745
}
4846

4947
#[test]
5048
fn test_wrong_address_1() {
51-
assert!(crate::run_server("tcpd:0.0.0.0:12345", 1).is_err());
49+
crate::run_server("tcpd:0.0.0.0:12345", 1).unwrap_err();
5250
}

0 commit comments

Comments
 (0)