Skip to content

Commit

Permalink
Test(config): Add coverage for EffectiveShipArgs by env
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
  • Loading branch information
PaulDance committed Aug 15, 2024
1 parent 0cdcbdf commit 30e4696
Showing 1 changed file with 140 additions and 2 deletions.
142 changes: 140 additions & 2 deletions src/config/effective_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl EffectiveShipArgs {

#[cfg(test)]
mod tests {
#![allow(clippy::needless_update)]
use std::fmt::Debug;

use super::*;
Expand Down Expand Up @@ -167,6 +168,31 @@ mod tests {
);
}

#[test]
fn test_effectiveshipargs_noconfig_envset_noargs_isenv() {
assert_eq!(
EffectiveShipArgs::new(
&UserConfig {
packages: BTreeMap::new(),
defaults: Some(DefaultsSection {
ship_cmd: ShipArgs::default()
}),
},
ShipArgs {
force: Some(false),
no_self: Some(true),
..Default::default()
},
ShipArgs::default(),
),
EffectiveShipArgs {
force: false,
no_self: true,
..Default::default()
},
);
}

#[test]
fn test_effectiveshipargs_noconfig_noenv_argsset_isargs() {
assert_eq!(
Expand All @@ -193,7 +219,7 @@ mod tests {
}

#[test]
fn test_effectiveshipargs_configset_noenv_argsset_nointersection_isunion() {
fn test_effectiveshipargs_configset_envset_argsset_nointersection_isunion() {
assert_eq!(
EffectiveShipArgs::new(
&UserConfig {
Expand All @@ -206,7 +232,10 @@ mod tests {
}
}),
},
ShipArgs::default(),
ShipArgs {
only_self: Some(true),
..Default::default()
},
ShipArgs {
no_fail_fast: Some(true),
skip_check: Some(false),
Expand All @@ -218,6 +247,75 @@ mod tests {
no_self: false,
no_fail_fast: true,
skip_check: false,
only_self: true,
..Default::default()
},
);
}

#[test]
fn test_effectiveshipargs_configset_envset_noargs_withintersection_envhasprecedence() {
assert_eq!(
EffectiveShipArgs::new(
&UserConfig {
packages: BTreeMap::new(),
defaults: Some(DefaultsSection {
ship_cmd: ShipArgs {
force: Some(true),
no_self: Some(false),
no_fail_fast: Some(true),
skip_check: Some(false),
..Default::default()
}
}),
},
ShipArgs {
force: Some(false),
no_self: Some(true),
no_fail_fast: Some(true),
skip_check: Some(false),
..Default::default()
},
ShipArgs::default(),
),
EffectiveShipArgs {
force: false,
no_self: true,
no_fail_fast: true,
skip_check: false,
..Default::default()
},
);
}

#[test]
fn test_effectiveshipargs_noconfig_envset_argsset_withintersection_argshaveprecedence() {
assert_eq!(
EffectiveShipArgs::new(
&UserConfig {
packages: BTreeMap::new(),
defaults: None,
},
ShipArgs {
force: Some(true),
no_self: Some(false),
no_fail_fast: Some(true),
skip_check: Some(false),
..Default::default()
},
ShipArgs {
force: Some(false),
no_self: Some(true),
no_fail_fast: Some(true),
skip_check: Some(false),
..Default::default()
},
),
EffectiveShipArgs {
force: false,
no_self: true,
no_fail_fast: true,
skip_check: false,
..Default::default()
},
);
Expand Down Expand Up @@ -257,4 +355,44 @@ mod tests {
},
);
}

#[test]
fn test_effectiveshipargs_configset_envset_argsset_withintersection_argshaveprecedence() {
assert_eq!(
EffectiveShipArgs::new(
&UserConfig {
packages: BTreeMap::new(),
defaults: Some(DefaultsSection {
ship_cmd: ShipArgs {
force: Some(true),
no_self: Some(false),
no_fail_fast: Some(true),
skip_check: Some(false),
..Default::default()
}
}),
},
ShipArgs {
only_self: Some(false),
..Default::default()
},
ShipArgs {
force: Some(false),
no_self: Some(true),
no_fail_fast: Some(true),
skip_check: Some(false),
only_self: Some(true),
..Default::default()
},
),
EffectiveShipArgs {
force: false,
no_self: true,
no_fail_fast: true,
skip_check: false,
only_self: true,
..Default::default()
},
);
}
}

0 comments on commit 30e4696

Please sign in to comment.