summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-26 19:59:39 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-26 23:52:48 -0400
commit53f2d63e53dccbfae435e01305327f2fcf84a0d4 (patch)
tree84b6b9db8faf7a1c0324304988455ace5fcf1cc8
parentc5ea65393d9b8000d68cf8c2f887f22bdae81222 (diff)
downloadclinte-53f2d63e53dccbfae435e01305327f2fcf84a0d4.tar.gz
using in-memory db for tests, passing path to logging::init() instead of assuming
-rw-r--r--src/db.rs2
-rw-r--r--src/logging.rs12
-rw-r--r--src/main.rs3
-rw-r--r--src/posts.rs2
4 files changed, 10 insertions, 9 deletions
diff --git a/src/db.rs b/src/db.rs
index 8ae9f2c..86875e2 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -59,7 +59,7 @@ mod tests {
 
     #[test]
     fn test_new() {
-        let conn = Conn::init("/tmp/clinte-test.db");
+        let conn = Conn::init(":memory:");
         let mut stmt = conn.prepare("SELECT * FROM POSTS").unwrap();
 
         stmt.query_map(rusqlite::NO_PARAMS, |_| Ok(())).unwrap();
diff --git a/src/logging.rs b/src/logging.rs
index 5699f59..346a7ab 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -3,11 +3,9 @@ use std::fs::OpenOptions;
 use simplelog::*;
 
 use crate::error;
-use crate::user;
 
-pub fn init() -> error::Result<()> {
-    let file = format!("/tmp/clinte_{}.log", *user::NAME);
-    let logfile = match OpenOptions::new().append(true).create(true).open(file) {
+pub fn init(path: &str) -> error::Result<()> {
+    let logfile = match OpenOptions::new().append(true).create(true).open(path) {
         Err(e) => {
             panic!("Could not open log file: {}", e);
         }
@@ -29,13 +27,15 @@ mod tests {
 
     #[test]
     fn init_logs() {
-        let file = format!("/tmp/clinte_{}.log", *user::NAME);
+        let file = "clinte_test.log";
         let blank = " ".bytes().collect::<Vec<u8>>();
         fs::write(&file, &blank).unwrap();
-        init().unwrap();
+        init("clinte_test.log").unwrap();
 
         log::info!("TEST LOG MESSAGE");
         let logfile = fs::read_to_string(&file).unwrap();
         assert!(logfile.contains("TEST LOG MESSAGE"));
+
+        fs::remove_file("clinte_test.log").unwrap();
     }
 }
diff --git a/src/main.rs b/src/main.rs
index faef1b3..474c117 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,7 +23,8 @@ fn main() -> error::Result<()> {
         .get_matches();
 
     let start = time::Instant::now();
-    logging::init()?;
+    let file = format!("/tmp/clinte_{}.log", *user::NAME);
+    logging::init(&file)?;
     log::info!("clinte starting up!");
     println!("clinte v{}", clap::crate_version!());
     println!("a community notices system");
diff --git a/src/posts.rs b/src/posts.rs
index 30738f0..e019454 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -207,7 +207,7 @@ mod tests {
 
     #[test]
     fn post_new() {
-        let db = db::Conn::init("/tmp/clinte.db");
+        let db = db::Conn::init(":memory:");
         let db = db::Conn { conn: db };
         let mut stmt = db
             .conn