|
| 1 | +use gix_config::Source; |
| 2 | +use std::path::Path; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn git_config_no_system() { |
| 6 | + assert_eq!( |
| 7 | + Source::GitInstallation.storage_location(&mut |name| { |
| 8 | + assert_eq!( |
| 9 | + name, "GIT_CONFIG_NOSYSTEM", |
| 10 | + "it only checks this var, and if set, nothing else" |
| 11 | + ); |
| 12 | + Some("1".into()) |
| 13 | + }), |
| 14 | + None |
| 15 | + ); |
| 16 | + assert_eq!( |
| 17 | + Source::System.storage_location(&mut |name| { |
| 18 | + assert_eq!( |
| 19 | + name, "GIT_CONFIG_NOSYSTEM", |
| 20 | + "it only checks this var, and if set, nothing else" |
| 21 | + ); |
| 22 | + Some("1".into()) |
| 23 | + }), |
| 24 | + None |
| 25 | + ); |
| 26 | +} |
| 27 | + |
| 28 | +#[test] |
| 29 | +fn git_config_system() { |
| 30 | + assert_eq!( |
| 31 | + Source::System |
| 32 | + .storage_location(&mut |name| { |
| 33 | + match name { |
| 34 | + "GIT_CONFIG_NOSYSTEM" => None, |
| 35 | + "GIT_CONFIG_SYSTEM" => Some("alternative".into()), |
| 36 | + unexpected => unreachable!("unexpected env var: {unexpected}"), |
| 37 | + } |
| 38 | + }) |
| 39 | + .expect("set") |
| 40 | + .as_ref(), |
| 41 | + Path::new("alternative"), |
| 42 | + "we respect the system config variable for overrides" |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +#[test] |
| 47 | +fn git_config_global() { |
| 48 | + for source in [Source::Git, Source::User] { |
| 49 | + assert_eq!( |
| 50 | + source |
| 51 | + .storage_location(&mut |name| { |
| 52 | + assert_eq!( |
| 53 | + name, "GIT_CONFIG_GLOBAL", |
| 54 | + "it only checks this var, and if set, nothing else" |
| 55 | + ); |
| 56 | + Some("alternative".into()) |
| 57 | + }) |
| 58 | + .expect("set") |
| 59 | + .as_ref(), |
| 60 | + Path::new("alternative"), |
| 61 | + "we respect the global config variable for 'git' overrides" |
| 62 | + ); |
| 63 | + } |
| 64 | +} |
0 commit comments