mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-25 04:11:53 +02:00
fix(tests): add Settings::utc() for utc settings (#1677)
Means we don't try and load timezones in tests, as this fails due to multiple threads. Also allow specifying '0' or 'utc' as a timezone
This commit is contained in:
parent
318bdd8955
commit
1993653102
@ -362,7 +362,7 @@ mod tests {
|
|||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
cwd_filter: RegexSet::new(["^/supasecret"]).unwrap(),
|
cwd_filter: RegexSet::new(["^/supasecret"]).unwrap(),
|
||||||
history_filter: RegexSet::new(["^psql"]).unwrap(),
|
history_filter: RegexSet::new(["^psql"]).unwrap(),
|
||||||
..Settings::default()
|
..Settings::utc()
|
||||||
};
|
};
|
||||||
|
|
||||||
let normal_command: History = History::capture()
|
let normal_command: History = History::capture()
|
||||||
@ -411,7 +411,7 @@ mod tests {
|
|||||||
fn disable_secrets() {
|
fn disable_secrets() {
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
secrets_filter: false,
|
secrets_filter: false,
|
||||||
..Settings::default()
|
..Settings::utc()
|
||||||
};
|
};
|
||||||
|
|
||||||
let stripe_key: History = History::capture()
|
let stripe_key: History = History::capture()
|
||||||
|
@ -155,6 +155,11 @@ impl FromStr for Timezone {
|
|||||||
return Ok(Self(offset));
|
return Ok(Self(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if matches!(s.to_lowercase().as_str(), "0" | "utc") {
|
||||||
|
let offset = UtcOffset::UTC;
|
||||||
|
return Ok(Self(offset));
|
||||||
|
}
|
||||||
|
|
||||||
// offset from UTC
|
// offset from UTC
|
||||||
if let Ok(offset) = UtcOffset::parse(s, OFFSET_FMT) {
|
if let Ok(offset) = UtcOffset::parse(s, OFFSET_FMT) {
|
||||||
return Ok(Self(offset));
|
return Ok(Self(offset));
|
||||||
@ -355,6 +360,17 @@ pub struct Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
pub fn utc() -> Self {
|
||||||
|
Self::builder()
|
||||||
|
.expect("Could not build default")
|
||||||
|
.set_override("timezone", "0")
|
||||||
|
.expect("failed to override timezone with UTC")
|
||||||
|
.build()
|
||||||
|
.expect("Could not build config")
|
||||||
|
.try_deserialize()
|
||||||
|
.expect("Could not deserialize config")
|
||||||
|
}
|
||||||
|
|
||||||
fn save_to_data_dir(filename: &str, value: &str) -> Result<()> {
|
fn save_to_data_dir(filename: &str, value: &str) -> Result<()> {
|
||||||
let data_dir = atuin_common::utils::data_dir();
|
let data_dir = atuin_common::utils::data_dir();
|
||||||
let data_dir = data_dir.as_path();
|
let data_dir = data_dir.as_path();
|
||||||
|
@ -182,7 +182,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn interesting_commands() {
|
fn interesting_commands() {
|
||||||
let settings = Settings::default();
|
let settings = Settings::utc();
|
||||||
|
|
||||||
assert_eq!(interesting_command(&settings, "cargo"), "cargo");
|
assert_eq!(interesting_command(&settings, "cargo"), "cargo");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -199,7 +199,7 @@ mod tests {
|
|||||||
// Test with spaces in the common_prefix
|
// Test with spaces in the common_prefix
|
||||||
#[test]
|
#[test]
|
||||||
fn interesting_commands_spaces() {
|
fn interesting_commands_spaces() {
|
||||||
let mut settings = Settings::default();
|
let mut settings = Settings::utc();
|
||||||
settings.stats.common_prefix.push("sudo test".to_string());
|
settings.stats.common_prefix.push("sudo test".to_string());
|
||||||
|
|
||||||
assert_eq!(interesting_command(&settings, "sudo test"), "sudo test");
|
assert_eq!(interesting_command(&settings, "sudo test"), "sudo test");
|
||||||
@ -224,7 +224,7 @@ mod tests {
|
|||||||
// Test with spaces in the common_subcommand
|
// Test with spaces in the common_subcommand
|
||||||
#[test]
|
#[test]
|
||||||
fn interesting_commands_spaces_subcommand() {
|
fn interesting_commands_spaces_subcommand() {
|
||||||
let mut settings = Settings::default();
|
let mut settings = Settings::utc();
|
||||||
settings
|
settings
|
||||||
.stats
|
.stats
|
||||||
.common_subcommands
|
.common_subcommands
|
||||||
@ -254,7 +254,7 @@ mod tests {
|
|||||||
// Test with spaces in the common_prefix and common_subcommand
|
// Test with spaces in the common_prefix and common_subcommand
|
||||||
#[test]
|
#[test]
|
||||||
fn interesting_commands_spaces_both() {
|
fn interesting_commands_spaces_both() {
|
||||||
let mut settings = Settings::default();
|
let mut settings = Settings::utc();
|
||||||
settings.stats.common_prefix.push("sudo test".to_string());
|
settings.stats.common_prefix.push("sudo test".to_string());
|
||||||
settings
|
settings
|
||||||
.stats
|
.stats
|
||||||
|
Loading…
x
Reference in New Issue
Block a user