Commit d67ffabb authored by MrMan's avatar MrMan

Start adding testing stuff, update actix_web

parent 90211a3b
This diff is collapsed.
......@@ -19,7 +19,11 @@ failure = "0.1.1"
askama = "0.6.4"
chrono = { version = "0.4", features = ["serde"] }
clap = "2.31.2"
actix-web = "0.6"
actix-web = "0.7.2"
uuid = { version = "0.6", features = ["v4"] }
rusqlite = { version = "0.13.0", features = ["bundled"] }
simple-signal = "1.1.1"
\ No newline at end of file
simple-signal = "1.1.1"
[dev-dependencies]
tempfile = "3"
smtp = "0.3.0"
\ No newline at end of file
......@@ -21,7 +21,7 @@ struct ComponentStatus {
state: &'static str,
}
fn api_index(_req: HttpRequest) -> Result<Json<APIStatus>> {
fn api_index(_req: &HttpRequest) -> Result<Json<APIStatus>> {
Ok(Json(APIStatus{
version: &env!("CARGO_PKG_VERSION")
}))
......
......@@ -5,10 +5,10 @@ pub fn app() -> App {
App::new()
.prefix("/")
.resource("/", |r| r.f(serve_index_html))
.handler("/js", StaticFiles::new("frontend/js"))
.handler("/images", StaticFiles::new("frontend/images"))
.handler("/js", StaticFiles::new("frontend/js").unwrap())
.handler("/images", StaticFiles::new("frontend/images").unwrap())
}
fn serve_index_html(_req: HttpRequest) -> Result<NamedFile> {
fn serve_index_html(_req: &HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open("frontend/index.html")?)
}
extern crate tempfile;
pub mod fixtures;
use rand::Rng;
use rand::distributions::Alphanumeric;
use rand::seq::sample_iter;
use std::net::TcpListener;
// Get available port
// https://elliotekj.com/2017/07/25/find-available-tcp-port-rust/
const TMP_PORT_RANGE_START: u16 = 8000;
const TMP_PORT_RANGE_END: u16 = 9000;
const STARTUP_EXTRA_WAIT: u64 = 100;
fn get_available_port() -> Option<u16> {
let mut rng = rand::thread_rng();
let mut available = false;
let mut port = 0;
while !available {
port = sample_iter(&mut rng, TMP_PORT_RANGE_START..TMP_PORT_RANGE_END, 1).unwrap()[0];
available = port_is_available(port);
}
Some(port)
}
fn port_is_available(port: u16) -> bool {
match TcpListener::bind(("127.0.0.1", port)) {
Ok(_) => true,
Err(_) => false,
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment