Skip to content

Commit

Permalink
cleanup after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dejankos committed Sep 17, 2020
1 parent 5158379 commit e64992a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{fs, thread};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;

use actix_web::{App, Error, test, web};
use actix_web::dev::ServiceResponse;
use actix_web::http::StatusCode;
use actix_web::rt as actix_rt;
use actix_web::{test, web, App, Error};

use crate::config::{DbConfig, RocksDbConfig};
use crate::conversion::bytes_to_str;
Expand Down Expand Up @@ -35,6 +35,12 @@ impl DbConfig {
}
}

impl Drop for DbManager {
fn drop(&mut self) {
let _ = fs::remove_dir_all(RocksDbConfig::default().path);
}
}

#[actix_rt::test]
async fn should_open_and_close_db() -> Result<(), Error> {
std::env::set_var("RUST_BACKTRACE", "full");
Expand All @@ -47,7 +53,7 @@ async fn should_open_and_close_db() -> Result<(), Error> {
.service(close)
.service(exists),
)
.await;
.await;

let req = test::TestRequest::post().uri("/test_db").to_request();
let res = test::call_service(&mut app, req).await;
Expand Down Expand Up @@ -92,7 +98,7 @@ async fn should_add_and_delete_record() -> Result<(), Error> {
.service(remove)
.service(close),
)
.await;
.await;

let req = test::TestRequest::post().uri("/test_db").to_request();
let res = test::call_service(&mut app, req).await;
Expand Down Expand Up @@ -153,7 +159,7 @@ async fn should_expire_record() -> Result<(), Error> {
.service(remove)
.service(close),
)
.await;
.await;

let req = test::TestRequest::post().uri("/test_db").to_request();
let res = test::call_service(&mut app, req).await;
Expand Down Expand Up @@ -213,7 +219,7 @@ async fn should_check_service_status() -> Result<(), Error> {
.app_data(web::Data::new(db_manager))
.service(health),
)
.await;
.await;

let req = test::TestRequest::get().uri("/health").to_request();
let res = test::call_service(&mut app, req).await;
Expand All @@ -237,7 +243,7 @@ async fn should_handle_404() -> Result<(), Error> {
.app_data(web::Data::new(db_manager))
.service(exists),
)
.await;
.await;

let req = test::TestRequest::put().uri("/test_db").to_request(); // no put handles
let res = test::call_service(&mut app, req).await;
Expand Down

0 comments on commit e64992a

Please sign in to comment.