Assert Taskwarrior data location is custom
This commit is contained in:
@@ -1,45 +1,25 @@
|
||||
use configparser::ini::Ini;
|
||||
use contextswitch_api::taskwarrior;
|
||||
use mktemp::Temp;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::net::TcpListener;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn spawn_app() -> String {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind random port");
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
|
||||
let server = contextswitch::run(listener).expect("Failed to bind address");
|
||||
let server = contextswitch_api::run(listener).expect("Failed to bind address");
|
||||
let _ = tokio::spawn(server);
|
||||
format!("http://127.0.0.1:{}", port)
|
||||
}
|
||||
|
||||
pub fn setup_tasks() -> PathBuf {
|
||||
let mut config = Ini::new();
|
||||
config.setstr("default", "uda.contextswitch.type", Some("string"));
|
||||
config.setstr(
|
||||
"default",
|
||||
"uda.contextswitch.label",
|
||||
Some("Context Switch metadata"),
|
||||
);
|
||||
config.setstr("default", "uda.contextswitch.default", Some("{}"));
|
||||
|
||||
pub fn setup_tasks() -> String {
|
||||
let tmp_dir = Temp::new_dir().unwrap();
|
||||
let task_data_path = tmp_dir.to_path_buf();
|
||||
config.setstr(
|
||||
"default",
|
||||
"data.location",
|
||||
Some(task_data_path.to_str().unwrap()),
|
||||
);
|
||||
|
||||
let taskrc_path = task_data_path.join(".taskrc");
|
||||
config.write(taskrc_path.as_path()).unwrap();
|
||||
env::set_var("TASKRC", taskrc_path.to_str().unwrap());
|
||||
|
||||
let task_data_location = taskwarrior::load_config(tmp_dir.to_str());
|
||||
tmp_dir.release();
|
||||
return task_data_path;
|
||||
|
||||
return task_data_location;
|
||||
}
|
||||
|
||||
pub fn clear_tasks(task_data_path: PathBuf) {
|
||||
fs::remove_dir_all(task_data_path).unwrap();
|
||||
pub fn clear_tasks(task_data_location: String) {
|
||||
fs::remove_dir_all(task_data_location).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user