ptth/src/lib.rs

56 lines
1.0 KiB
Rust

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";
// Basically binaries, but in the lib we can do experimental
// test stuff like spawn them both in the same process
pub mod relay;
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");
});
}
}