Start adding some tests
							parent
							
								
									41213f7272
								
							
						
					
					
						commit
						5d14155ba3
					
				
							
								
								
									
										46
									
								
								src/lib.rs
								
								
								
								
							
							
						
						
									
										46
									
								
								src/lib.rs
								
								
								
								
							|  | @ -1,5 +1,10 @@ | ||||||
| pub mod http_serde; | pub mod http_serde; | ||||||
| 
 | 
 | ||||||
|  | // It's easier if the server can stream its response body
 | ||||||
|  | // back to the relay un-changed inside its request body
 | ||||||
|  | // So we wrap the server's actual response head
 | ||||||
|  | // (status code, headers, etc.) in this one header field.
 | ||||||
|  | 
 | ||||||
| pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; | pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; | ||||||
| 
 | 
 | ||||||
| // Basically binaries, but in the lib we can do experimental
 | // Basically binaries, but in the lib we can do experimental
 | ||||||
|  | @ -7,3 +12,44 @@ pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; | ||||||
| 
 | 
 | ||||||
| pub mod relay; | pub mod relay; | ||||||
| pub mod server; | pub mod server; | ||||||
|  | 
 | ||||||
|  | #[cfg (test)] | ||||||
|  | mod tests { | ||||||
|  | 	use std::{ | ||||||
|  | 		error::Error, | ||||||
|  | 		time::Duration, | ||||||
|  | 	}; | ||||||
|  | 	
 | ||||||
|  | 	use tokio::{ | ||||||
|  | 		prelude::*, | ||||||
|  | 		runtime::Runtime, | ||||||
|  | 		spawn, | ||||||
|  | 		time::delay_for, | ||||||
|  | 	}; | ||||||
|  | 	
 | ||||||
|  | 	use super::{ | ||||||
|  | 		relay, | ||||||
|  | 		server, | ||||||
|  | 	}; | ||||||
|  | 	
 | ||||||
|  | 	#[test] | ||||||
|  | 	fn end_to_end () { | ||||||
|  | 		use reqwest::Client; | ||||||
|  | 		
 | ||||||
|  | 		let mut rt = Runtime::new ().unwrap (); | ||||||
|  | 		
 | ||||||
|  | 		// Spawn the root task
 | ||||||
|  | 		rt.block_on (async { | ||||||
|  | 			spawn (async { | ||||||
|  | 				relay::main ().await.unwrap (); | ||||||
|  | 			}); | ||||||
|  | 			
 | ||||||
|  | 			let client = Client::new (); | ||||||
|  | 			
 | ||||||
|  | 			let resp = client.get ("http://127.0.0.1:4000/relay_up_check") | ||||||
|  | 			.send ().await.unwrap ().bytes ().await.unwrap (); | ||||||
|  | 			
 | ||||||
|  | 			assert_eq! (resp, "Relay is up\n"); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -241,6 +241,9 @@ async fn handle_all (req: Request <Body>, state: Arc <ServerState>) | ||||||
| 			Ok (status_reply (StatusCode::BAD_REQUEST, "Bad URI format")) | 			Ok (status_reply (StatusCode::BAD_REQUEST, "Bad URI format")) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	else if path == "/relay_up_check" { | ||||||
|  | 		Ok (status_reply (StatusCode::OK, "Relay is up\n")) | ||||||
|  | 	} | ||||||
| 	else { | 	else { | ||||||
| 		Ok (status_reply (StatusCode::OK, "Hi\n")) | 		Ok (status_reply (StatusCode::OK, "Hi\n")) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 _
						_