Skip to content

Commit d7ab2d9

Browse files
committed
rename determine_port_to_bind to find_port
and rename `bind` variable names to `port`
1 parent 9f5a54f commit d7ab2d9

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

tests/chunked-encode-large.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const TEXT: &'static str = concat![
6868

6969
#[async_std::test]
7070
async fn chunked_large() -> Result<(), http_types::Error> {
71-
let bind = test_utils::determine_port_to_bind().await;
71+
let bind = test_utils::find_port().await;
7272
let server = task::spawn(async move {
7373
let mut app = tide::new();
7474
app.at("/").get(|mut _req: tide::Request<()>| async {

tests/chunked-encode-small.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const TEXT: &'static str = concat![
1717

1818
#[async_std::test]
1919
async fn chunked_large() -> Result<(), http_types::Error> {
20-
let bind = test_utils::determine_port_to_bind().await;
20+
let port = test_utils::find_port().await;
2121
let server = task::spawn(async move {
2222
let mut app = tide::new();
2323
app.at("/").get(|mut _req: tide::Request<()>| async move {
@@ -27,13 +27,13 @@ async fn chunked_large() -> Result<(), http_types::Error> {
2727
.set_header(headers::CONTENT_TYPE, "text/plain; charset=utf-8");
2828
Ok(res)
2929
});
30-
app.listen(&bind).await?;
30+
app.listen(&port).await?;
3131
Result::<(), http_types::Error>::Ok(())
3232
});
3333

3434
let client = task::spawn(async move {
3535
task::sleep(Duration::from_millis(100)).await;
36-
let mut res = surf::get(format!("http://{}", bind)).await?;
36+
let mut res = surf::get(format!("http://{}", port)).await?;
3737
assert_eq!(res.status(), 200);
3838
assert_eq!(
3939
res.header(&"transfer-encoding".parse().unwrap()),

tests/server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ use serde::{Deserialize, Serialize};
99
#[test]
1010
fn hello_world() -> Result<(), http_types::Error> {
1111
task::block_on(async {
12-
let bind = test_utils::determine_port_to_bind().await;
12+
let port = test_utils::find_port().await;
1313
let server = task::spawn(async move {
1414
let mut app = tide::new();
1515
app.at("/").get(|mut req: tide::Request<()>| async move {
1616
assert_eq!(req.body_string().await.unwrap(), "nori".to_string());
1717
let res = tide::Response::new(StatusCode::Ok).body_string("says hello".to_string());
1818
Ok(res)
1919
});
20-
app.listen(&bind).await?;
20+
app.listen(&port).await?;
2121
Result::<(), http_types::Error>::Ok(())
2222
});
2323

2424
let client = task::spawn(async move {
2525
task::sleep(Duration::from_millis(100)).await;
26-
let string = surf::get(format!("http://{}", bind))
26+
let string = surf::get(format!("http://{}", port))
2727
.body_string("nori".to_string())
2828
.recv_string()
2929
.await?;
@@ -38,18 +38,18 @@ fn hello_world() -> Result<(), http_types::Error> {
3838
#[test]
3939
fn echo_server() -> Result<(), http_types::Error> {
4040
task::block_on(async {
41-
let bind = test_utils::determine_port_to_bind().await;
41+
let port = test_utils::find_port().await;
4242
let server = task::spawn(async move {
4343
let mut app = tide::new();
4444
app.at("/").get(|req| async move { Ok(req) });
4545

46-
app.listen(&bind).await?;
46+
app.listen(&port).await?;
4747
Result::<(), http_types::Error>::Ok(())
4848
});
4949

5050
let client = task::spawn(async move {
5151
task::sleep(Duration::from_millis(100)).await;
52-
let string = surf::get(format!("http://{}", bind))
52+
let string = surf::get(format!("http://{}", port))
5353
.body_string("chashu".to_string())
5454
.recv_string()
5555
.await?;
@@ -69,7 +69,7 @@ fn json() -> Result<(), http_types::Error> {
6969
}
7070

7171
task::block_on(async {
72-
let bind = test_utils::determine_port_to_bind().await;
72+
let port = test_utils::find_port().await;
7373
let server = task::spawn(async move {
7474
let mut app = tide::new();
7575
app.at("/").get(|mut req: tide::Request<()>| async move {
@@ -79,13 +79,13 @@ fn json() -> Result<(), http_types::Error> {
7979
let res = tide::Response::new(StatusCode::Ok).body_json(&counter)?;
8080
Ok(res)
8181
});
82-
app.listen(&bind).await?;
82+
app.listen(&port).await?;
8383
Result::<(), http_types::Error>::Ok(())
8484
});
8585

8686
let client = task::spawn(async move {
8787
task::sleep(Duration::from_millis(100)).await;
88-
let counter: Counter = surf::get(format!("http://{}", &bind))
88+
let counter: Counter = surf::get(format!("http://{}", &port))
8989
.body_json(&Counter { count: 0 })?
9090
.recv_json()
9191
.await?;

tests/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub async fn determine_port_to_bind() -> async_std::net::SocketAddr {
1+
pub async fn find_port() -> async_std::net::SocketAddr {
22
async_std::net::TcpListener::bind("localhost:0")
33
.await
44
.unwrap()

0 commit comments

Comments
 (0)