#![allow(unused_crate_dependencies)]
use serial_test::serial;
use tempfile;
use volli_agent::{export_profile, import_profile, load_state, save_state};
#[test]
#[serial]
fn export_import_roundtrip() {
let dir = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", dir.path());
}
save_state("p1", "secret1").unwrap();
let yaml = export_profile("p1").unwrap();
let new = import_profile(&yaml, Some("p2"), false).unwrap();
assert_eq!(new, "p2");
assert_eq!(load_state("p2").unwrap().unwrap(), "secret1");
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}
#[test]
#[serial]
fn import_conflict_and_force() {
let dir = tempfile::tempdir().unwrap();
unsafe {
std::env::set_var("VOLLI_CONFIG_DIR", dir.path());
}
save_state("p1", "s1").unwrap();
let yaml = export_profile("p1").unwrap();
assert!(import_profile(&yaml, Some("p1"), false).is_err());
save_state("p1", "old").unwrap();
let name = import_profile(&yaml, Some("p1"), true).unwrap();
assert_eq!(name, "p1");
assert_eq!(load_state("p1").unwrap().unwrap(), "s1");
unsafe {
std::env::remove_var("VOLLI_CONFIG_DIR");
}
}