Skip to content

Commit 43373f2

Browse files
committed
Isolate configuration tests by not using the default configuration which depends on the local environment
1 parent 2a09eda commit 43373f2

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/config.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@ impl Default for Config {
4444
}
4545

4646
impl Config {
47-
/// Load the configuration from a TOML file at the given path.
47+
/// Load the configuration from a TOML file, using defaults for values that were not provided.
4848
pub fn load(path: &Path) -> figment::Result<Self> {
4949
Figment::from(Serialized::defaults(Config::default()))
5050
.admerge(Toml::file(path))
5151
.extract()
5252
}
5353

54-
/// Create the configuration from a TOML string.
55-
fn from_toml(toml: &str) -> figment::Result<Self> {
56-
Figment::from(Serialized::defaults(Config::default()))
57-
.admerge(Toml::string(toml))
58-
.extract()
54+
/// Load the configuration from a figment provider without using any defaults.
55+
#[cfg(test)]
56+
fn _load_from_provider(provider: impl figment::Provider) -> figment::Result<Self> {
57+
Figment::from(provider).extract()
5958
}
6059

6160
/// Save the configuration.
@@ -116,6 +115,7 @@ mod tests {
116115
use super::*;
117116
use indoc::indoc;
118117

118+
/// The example configuration is rendered correctly.
119119
#[test]
120120
fn example_config() {
121121
let toml = indoc! {r#"
@@ -175,25 +175,31 @@ mod tests {
175175
]),
176176
local: Some(vec!["jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw".parse().unwrap()]),
177177
sources: Some(vec![
178-
Source {
179-
name: "github".to_string(),
180-
provider: GitProviderType::Github,
181-
url: "https://api.github.com".to_string(),
182-
},
183-
Source {
184-
name: "gitlab".to_string(),
185-
provider: GitProviderType::Gitlab,
186-
url: "https://gitlab.com".to_string(),
187-
},
188178
Source {
189179
name: "acme-corp".to_string(),
190180
provider: GitProviderType::Gitlab,
191181
url: "https://git.acme.corp".to_string(),
192-
},
182+
}
193183
])
194184
};
195185

196-
let config = Config::from_toml(toml).unwrap();
186+
let config = Config::_load_from_provider(Toml::string(toml)).unwrap();
197187
assert_eq!(config, expected);
198188
}
189+
190+
/// The default configuration contains the default GitHub and GitLab sources.
191+
#[test]
192+
fn default_configuration_contains_default_sources() {
193+
let default_sources = Config::default().sources.unwrap();
194+
assert!(default_sources.contains(&Source {
195+
name: "github".to_string(),
196+
provider: GitProviderType::Github,
197+
url: "https://api.github.com".to_string(),
198+
}));
199+
assert!(default_sources.contains(&Source {
200+
name: "gitlab".to_string(),
201+
provider: GitProviderType::Gitlab,
202+
url: "https://gitlab.com".to_string(),
203+
}));
204+
}
199205
}

0 commit comments

Comments
 (0)