@@ -44,18 +44,17 @@ impl Default for Config {
44
44
}
45
45
46
46
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 .
48
48
pub fn load ( path : & Path ) -> figment:: Result < Self > {
49
49
Figment :: from ( Serialized :: defaults ( Config :: default ( ) ) )
50
50
. admerge ( Toml :: file ( path) )
51
51
. extract ( )
52
52
}
53
53
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 ( )
59
58
}
60
59
61
60
/// Save the configuration.
@@ -116,6 +115,7 @@ mod tests {
116
115
use super :: * ;
117
116
use indoc:: indoc;
118
117
118
+ /// The example configuration is rendered correctly.
119
119
#[ test]
120
120
fn example_config ( ) {
121
121
let toml = indoc ! { r#"
@@ -175,25 +175,31 @@ mod tests {
175
175
] ) ,
176
176
local : Some ( vec ! [ "jdoe@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJHDGMF+tZQL3dcr1arPst+YP8v33Is0kAJVvyTKrxMw" . parse( ) . unwrap( ) ] ) ,
177
177
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
- } ,
188
178
Source {
189
179
name: "acme-corp" . to_string( ) ,
190
180
provider: GitProviderType :: Gitlab ,
191
181
url: "https://git.acme.corp" . to_string( ) ,
192
- } ,
182
+ }
193
183
] )
194
184
} ;
195
185
196
- let config = Config :: from_toml ( toml) . unwrap ( ) ;
186
+ let config = Config :: _load_from_provider ( Toml :: string ( toml) ) . unwrap ( ) ;
197
187
assert_eq ! ( config, expected) ;
198
188
}
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
+ }
199
205
}
0 commit comments