replaced server address with a constant
This commit is contained in:
parent
6203112195
commit
28847873f6
2 changed files with 9 additions and 7 deletions
|
@ -4,14 +4,16 @@ mod modules;
|
||||||
|
|
||||||
use std::net::{TcpListener, TcpStream, Shutdown};
|
use std::net::{TcpListener, TcpStream, Shutdown};
|
||||||
|
|
||||||
|
const SERVER_ADDRESS: &str = "localhost:5000";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let listener = make_listener(String::from("localhost:5000"));
|
let listener = make_listener(SERVER_ADDRESS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
drop(listener);
|
drop(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_listener(address: String) -> TcpListener {
|
fn make_listener(address: &str) -> TcpListener {
|
||||||
TcpListener::bind(address).unwrap()
|
TcpListener::bind(address).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::make_listener;
|
use crate::{make_listener, SERVER_ADDRESS};
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -9,16 +9,16 @@ fn it_works() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_make_socket_listener(){
|
fn can_make_socket_listener(){
|
||||||
let listener = make_listener(String::from("localhost:5000"));
|
let listener = make_listener(SERVER_ADDRESS);
|
||||||
drop(listener);
|
drop(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_and_connect_to_listener() {
|
fn create_and_connect_to_listener() {
|
||||||
let listener = make_listener(String::from("localhost:5000"));
|
let listener = make_listener(SERVER_ADDRESS);
|
||||||
|
|
||||||
let join_handle = std::thread::spawn(move || {
|
let join_handle = std::thread::spawn(move || {
|
||||||
let _outgoing = std::net::TcpStream::connect("localhost:5000").unwrap();
|
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
||||||
});
|
});
|
||||||
join_handle.join().unwrap();
|
join_handle.join().unwrap();
|
||||||
drop(listener);
|
drop(listener);
|
||||||
|
@ -27,6 +27,6 @@ fn create_and_connect_to_listener() {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn panic_no_listener() {
|
fn panic_no_listener() {
|
||||||
let _outgoing = std::net::TcpStream::connect("localhost:5000").unwrap();
|
let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue