prevent editing a tracked database in tests

This commit is contained in:
Abraham Toriz 2021-08-04 18:40:35 -05:00
parent b767d9e476
commit 8b9f510097
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 16 additions and 1 deletions

View File

@ -122,9 +122,12 @@ impl<'a> Command<'a> for EditCommand {
#[cfg(test)]
mod tests {
use std::fs;
use pretty_assertions::assert_eq;
use chrono::{Duration, TimeZone};
use ansi_term::Color::Yellow;
use tempfile::NamedTempFile;
use crate::database::SqliteDatabase;
use crate::test_utils::Ps;
@ -349,11 +352,20 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&err)), Ps(""));
}
fn copy_db(path: &str) -> NamedTempFile {
let tmpfile = NamedTempFile::new().unwrap();
fs::copy(path, &tmpfile).unwrap();
tmpfile
}
#[test]
fn warn_old() {
std::env::set_var("TZ", "UTC");
let mut db = SqliteDatabase::from_path("assets/test_old_db.db").unwrap();
let database_file = copy_db("assets/test_old_db.db");
let mut db = SqliteDatabase::from_path(&database_file).unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
let now = Utc.ymd(2021, 8, 3).and_hms(20, 29, 0);
@ -376,5 +388,8 @@ mod tests {
String::from_utf8_lossy(&err),
format!("{} You are using the old timetrap format, it is advised that you update your database using t migrate\n", Yellow.bold().paint("[WARNING]")),
);
std::mem::drop(db);
std::mem::drop(database_file);
}
}