prevent editing a tracked database in tests
This commit is contained in:
parent
b767d9e476
commit
8b9f510097
|
@ -122,9 +122,12 @@ impl<'a> Command<'a> for EditCommand {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use chrono::{Duration, TimeZone};
|
use chrono::{Duration, TimeZone};
|
||||||
use ansi_term::Color::Yellow;
|
use ansi_term::Color::Yellow;
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use crate::database::SqliteDatabase;
|
use crate::database::SqliteDatabase;
|
||||||
use crate::test_utils::Ps;
|
use crate::test_utils::Ps;
|
||||||
|
@ -349,11 +352,20 @@ mod tests {
|
||||||
assert_eq!(Ps(&String::from_utf8_lossy(&err)), Ps(""));
|
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]
|
#[test]
|
||||||
fn warn_old() {
|
fn warn_old() {
|
||||||
std::env::set_var("TZ", "UTC");
|
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 out = Vec::new();
|
||||||
let mut err = Vec::new();
|
let mut err = Vec::new();
|
||||||
let now = Utc.ymd(2021, 8, 3).and_hms(20, 29, 0);
|
let now = Utc.ymd(2021, 8, 3).and_hms(20, 29, 0);
|
||||||
|
@ -376,5 +388,8 @@ mod tests {
|
||||||
String::from_utf8_lossy(&err),
|
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]")),
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue