Skip to content

Commit 16d8970

Browse files
committed
tests: tidy up test server usage
* Remove the `CHAIN` const and tuple from `TEST_SERVER` - this is now encapsulated in the `ClientConfig` that's returned from `make_configs()` and no tests are constructing a config from scratch. Similarly the domain name is always `"foobar.com"` (this is baked into the vendored end-entity certificate). Let's just use a const for that. * Remove `start_server()` - it's too small to be of much utility. Let's just ref the `lazy_static!` directly.
1 parent 5690851 commit 16d8970

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

tests/test.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ use tokio::sync::oneshot;
1414
use tokio::{runtime, time};
1515
use tokio_rustls::{LazyConfigAcceptor, TlsAcceptor, TlsConnector};
1616

17-
const CHAIN: &[u8] = include_bytes!("certs/end.chain");
18-
1917
lazy_static! {
20-
static ref TEST_SERVER: (SocketAddr, &'static str, &'static [u8]) = {
18+
static ref TEST_SERVER: SocketAddr = {
2119
let (config, _) = utils::make_configs();
2220
let acceptor = TlsAcceptor::from(Arc::new(config));
2321

@@ -59,15 +57,10 @@ lazy_static! {
5957
runtime.block_on(done);
6058
});
6159

62-
let addr = recv.recv().unwrap();
63-
(addr, "foobar.com", CHAIN)
60+
recv.recv().unwrap()
6461
};
6562
}
6663

67-
fn start_server() -> &'static (SocketAddr, &'static str, &'static [u8]) {
68-
&TEST_SERVER
69-
}
70-
7164
async fn start_client(addr: SocketAddr, domain: &str, config: Arc<ClientConfig>) -> io::Result<()> {
7265
const FILE: &[u8] = include_bytes!("../README.md");
7366

@@ -88,8 +81,6 @@ async fn start_client(addr: SocketAddr, domain: &str, config: Arc<ClientConfig>)
8881

8982
#[tokio::test]
9083
async fn pass() -> io::Result<()> {
91-
let (addr, domain, _) = start_server();
92-
9384
// TODO: not sure how to resolve this right now but since
9485
// TcpStream::bind now returns a future it creates a race
9586
// condition until its ready sometimes.
@@ -99,20 +90,18 @@ async fn pass() -> io::Result<()> {
9990
let (_, config) = utils::make_configs();
10091
let config = Arc::new(config);
10192

102-
start_client(*addr, domain, config).await?;
93+
start_client(*TEST_SERVER, utils::TEST_SERVER_DOMAIN, config).await?;
10394

10495
Ok(())
10596
}
10697

10798
#[tokio::test]
10899
async fn fail() -> io::Result<()> {
109-
let (addr, domain, _) = start_server();
110-
111100
let (_, config) = utils::make_configs();
112101
let config = Arc::new(config);
113102

114-
assert_ne!(domain, &"google.com");
115-
let ret = start_client(*addr, "google.com", config).await;
103+
assert_ne!(utils::TEST_SERVER_DOMAIN, "google.com");
104+
let ret = start_client(*TEST_SERVER, "google.com", config).await;
116105
assert!(ret.is_err());
117106

118107
Ok(())

tests/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ mod utils {
6060

6161
Ok(())
6262
}
63+
64+
#[allow(dead_code)]
65+
pub const TEST_SERVER_DOMAIN: &str = "foobar.com";
6366
}

0 commit comments

Comments
 (0)