From 28847873f696534cff61d9acdf2d245f93dccf03 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:55:00 -0800 Subject: [PATCH] replaced server address with a constant --- src/main.rs | 6 ++++-- src/tests/main_tests.rs | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2beb8b1..d4bbdf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,16 @@ mod modules; use std::net::{TcpListener, TcpStream, Shutdown}; +const SERVER_ADDRESS: &str = "localhost:5000"; + fn main() { - let listener = make_listener(String::from("localhost:5000")); + let listener = make_listener(SERVER_ADDRESS); drop(listener); } -fn make_listener(address: String) -> TcpListener { +fn make_listener(address: &str) -> TcpListener { TcpListener::bind(address).unwrap() } diff --git a/src/tests/main_tests.rs b/src/tests/main_tests.rs index da24d53..f31afb9 100644 --- a/src/tests/main_tests.rs +++ b/src/tests/main_tests.rs @@ -1,4 +1,4 @@ -use crate::make_listener; +use crate::{make_listener, SERVER_ADDRESS}; #[test] @@ -9,16 +9,16 @@ fn it_works() { #[test] fn can_make_socket_listener(){ - let listener = make_listener(String::from("localhost:5000")); + let listener = make_listener(SERVER_ADDRESS); drop(listener); } #[test] 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 _outgoing = std::net::TcpStream::connect("localhost:5000").unwrap(); + let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap(); }); join_handle.join().unwrap(); drop(listener); @@ -27,6 +27,6 @@ fn create_and_connect_to_listener() { #[test] #[should_panic] fn panic_no_listener() { - let _outgoing = std::net::TcpStream::connect("localhost:5000").unwrap(); + let _outgoing = std::net::TcpStream::connect(SERVER_ADDRESS).unwrap(); }