use configuration;
use std::fs;
use std::path;
use testing::temp;
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
struct TestConfiguration {
foo: String,
}
lazy_static! {
static ref TEST_IDENTIFIER: configuration::Identifier = configuration::Identifier {
application: "bdrck_config".to_owned(),
name: "test".to_owned(),
};
}
#[test]
fn test_persistence() {
::init().unwrap();
let file = temp::File::new_file().unwrap();
let path: path::PathBuf = file.path().to_owned();
fs::remove_file(path.as_path()).unwrap();
let default = TestConfiguration {
foo: "this is test data".to_owned(),
};
configuration::new(
TEST_IDENTIFIER.clone(),
default.clone(),
Some(path.as_path()),
).ok()
.unwrap();
assert_eq!(default, configuration::get(&TEST_IDENTIFIER).ok().unwrap());
let updated = TestConfiguration {
foo: "this is some other test data".to_owned(),
};
configuration::set(&TEST_IDENTIFIER, updated.clone())
.ok()
.unwrap();
assert_eq!(updated, configuration::get(&TEST_IDENTIFIER).ok().unwrap());
configuration::remove::<TestConfiguration>(&TEST_IDENTIFIER)
.ok()
.unwrap();
configuration::new(
TEST_IDENTIFIER.clone(),
default.clone(),
Some(path.as_path()),
).ok()
.unwrap();
assert_eq!(updated, configuration::get(&TEST_IDENTIFIER).ok().unwrap());
configuration::reset::<TestConfiguration>(&TEST_IDENTIFIER)
.ok()
.unwrap();
assert_eq!(default, configuration::get(&TEST_IDENTIFIER).ok().unwrap());
}