Skip to content

Commit 7c69bec

Browse files
committed
tests/util/chaosproxy: Replace unwrap() calls in proxy_database_url() fn with ? operator
1 parent 6da99e2 commit 7c69bec

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/tests/util/chaosproxy.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Context;
1+
use anyhow::{anyhow, Context};
22
use std::net::SocketAddr;
33
use std::sync::Arc;
44
use tokio::{
@@ -57,11 +57,18 @@ impl ChaosProxy {
5757
.context("could not resolve database url")?
5858
.first()
5959
.copied()
60-
.ok_or_else(|| anyhow::anyhow!("the database url does not point to any IP"))?;
60+
.ok_or_else(|| anyhow!("the database url does not point to any IP"))?;
61+
62+
let instance = ChaosProxy::new(backend_addr)?;
63+
64+
db_url
65+
.set_ip_host(instance.address.ip())
66+
.map_err(|_| anyhow!("Failed to set IP host on the URL"))?;
67+
68+
db_url
69+
.set_port(Some(instance.address.port()))
70+
.map_err(|_| anyhow!("Failed to set post on the URL"))?;
6171

62-
let instance = ChaosProxy::new(backend_addr).unwrap();
63-
db_url.set_ip_host(instance.address.ip()).unwrap();
64-
db_url.set_port(Some(instance.address.port())).unwrap();
6572
Ok((instance, db_url.into()))
6673
}
6774

0 commit comments

Comments
 (0)