aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-23 22:24:52 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-24 15:21:32 -0700
commit32e69d59150a2badfd72c62753414cbb1eb37c73 (patch)
treec8d355272f23abf20fbcdf6b583ad5740282d58e /rust/src
parent402cf5ebbd87b4e4de2d5ba83a97e7f9b014dfc9 (diff)
downloadfatcat-32e69d59150a2badfd72c62753414cbb1eb37c73.tar.gz
fatcat-32e69d59150a2badfd72c62753414cbb1eb37c73.zip
basic test for editgroup accept
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/lib.rs31
1 files changed, 18 insertions, 13 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 4e1dc8ba..c12575a9 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -36,7 +36,7 @@ pub use errors::*;
pub use self::errors::*;
use diesel::pg::PgConnection;
use diesel::prelude::*;
-use diesel::r2d2::{ConnectionManager, ManageConnection};
+use diesel::r2d2::ConnectionManager;
use dotenv::dotenv;
use iron::middleware::AfterMiddleware;
use iron::{Request, Response};
@@ -59,25 +59,30 @@ pub fn establish_connection() -> PgConnection {
/// Instantiate a new API server with a pooled database connection
pub fn server() -> Result<api_server::Server> {
dotenv().ok();
- let database_url = if cfg!(test) {
- env::var("DATABASE_URL").expect("DATABASE_URL must be set")
- } else {
- env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set")
- };
+ let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::<PgConnection>::new(database_url);
- if cfg!(test) {
- // run migrations; revert latest (dummy data); re-run latest
- let conn = manager.connect().unwrap();
- diesel_migrations::run_pending_migrations(&conn).unwrap();
- diesel_migrations::revert_latest_migration(&conn).unwrap();
- diesel_migrations::run_pending_migrations(&conn).unwrap();
- }
let pool = diesel::r2d2::Pool::builder()
.build(manager)
.expect("Failed to create database pool.");
Ok(api_server::Server { db_pool: pool })
}
+pub fn test_server() -> Result<api_server::Server> {
+
+ dotenv().ok();
+ let database_url = env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set");
+ env::set_var("DATABASE_URL", database_url);
+
+ let server = server()?;
+ let conn = server.db_pool.get().expect("db_pool error");
+
+ // run migrations; revert latest (dummy data); re-run latest
+ diesel_migrations::run_pending_migrations(&conn).unwrap();
+ diesel_migrations::revert_latest_migration(&conn).unwrap();
+ diesel_migrations::run_pending_migrations(&conn).unwrap();
+ Ok(server)
+}
+
/// HTTP header middleware
header! { (XClacksOverhead, "X-Clacks-Overhead") => [String] }