refactor sync server to use pluggable storage
..with a fixed implementation of the replica / server protocol logic. There isn't much logic yet, and there's a lot of boilerplate to take care of, so this looks a little lopsided, but I'm confident this is the right structure for this code's future.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
use crate::storage::{InMemoryStorage, Storage};
|
||||
use actix_web::{get, web, App, HttpServer, Responder, Scope};
|
||||
use api::{api_scope, ServerState};
|
||||
use server::{InMemorySyncServer, SyncServer};
|
||||
|
||||
mod api;
|
||||
mod server;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
mod storage;
|
||||
|
||||
// TODO: use hawk to sign requests
|
||||
|
||||
@@ -27,7 +25,7 @@ pub(crate) fn app_scope(server_state: ServerState) -> Scope {
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let server_box: Box<dyn SyncServer> = Box::new(InMemorySyncServer::new());
|
||||
let server_box: Box<dyn Storage> = Box::new(InMemoryStorage::new());
|
||||
let server_state = ServerState::new(server_box);
|
||||
|
||||
HttpServer::new(move || App::new().service(app_scope(server_state.clone())))
|
||||
@@ -35,3 +33,22 @@ async fn main() -> std::io::Result<()> {
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::api::ServerState;
|
||||
use crate::storage::{InMemoryStorage, Storage};
|
||||
use actix_web::{test, App};
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_index_get() {
|
||||
let server_box: Box<dyn Storage> = Box::new(InMemoryStorage::new());
|
||||
let server_state = ServerState::new(server_box);
|
||||
let mut app = test::init_service(App::new().service(app_scope(server_state))).await;
|
||||
|
||||
let req = test::TestRequest::get().uri("/").to_request();
|
||||
let resp = test::call_service(&mut app, req).await;
|
||||
assert!(resp.status().is_success());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user