@@ -162,12 +162,11 @@ fn format_change(input: &str, input_source: &str) -> Result<String> {
162162 serde_json:: to_string ( & json_inner) . context ( error:: JsonSerializeSnafu { input_source } )
163163}
164164
165- pub ( crate ) mod error {
165+ mod error {
166166 use snafu:: Snafu ;
167167
168168 #[ derive( Debug , Snafu ) ]
169- #[ snafu( visibility( pub ( crate ) ) ) ]
170-
169+ #[ snafu( visibility( pub ( super ) ) ) ]
171170 pub enum Error {
172171 #[ snafu( display( "Failed to commit combined settings to '{}': {}" , uri, source) ) ]
173172 CommitApply {
@@ -233,17 +232,15 @@ pub(crate) mod error {
233232 source : reqwest:: Error ,
234233 } ,
235234
236- #[ snafu( display( "Given invalid file URI '{}'" , input_source) ) ]
237- InvalidFileUri { input_source : String } ,
238-
239235 #[ snafu( display(
240236 "Failed to translate TOML from '{}' to JSON for API: {}" ,
241237 input_source,
242238 source
243239 ) ) ]
244240 TomlToJson {
245241 input_source : String ,
246- source : toml:: de:: Error ,
242+ #[ snafu( source( from( toml:: de:: Error , Box :: new) ) ) ]
243+ source : Box < toml:: de:: Error > ,
247244 } ,
248245
249246 #[ snafu( display( "Given invalid URI '{}': {}" , input_source, source) ) ]
@@ -253,11 +250,34 @@ pub(crate) mod error {
253250 } ,
254251
255252 #[ snafu( display( "Resolver failed: {}" , source) ) ]
256- ResolverFailure { source : crate :: uri_resolver:: ResolverError } ,
257-
253+ ResolverFailure {
254+ #[ snafu( source( from( crate :: uri_resolver:: ResolverError , Box :: new) ) ) ]
255+ source : Box < crate :: uri_resolver:: ResolverError > ,
256+ } ,
258257 }
259-
260258}
261259pub use error:: Error ;
262260pub type Result < T > = std:: result:: Result < T , error:: Error > ;
263261
262+ #[ cfg( test) ]
263+ mod resolver_selection_tests {
264+ use super :: select_resolver;
265+ use crate :: apply:: SettingsInput ;
266+ use std:: any:: { Any , TypeId } ;
267+ use test_case:: test_case;
268+
269+ #[ test_case( "-" , TypeId :: of:: <crate :: uri_resolver:: StdinUri >( ) ; "stdin" ) ]
270+ #[ test_case( "file:///tmp/foo" , TypeId :: of:: <crate :: uri_resolver:: FileUri >( ) ; "file" ) ]
271+ #[ test_case( "http://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "http" ) ]
272+ #[ test_case( "https://amazon.com" , TypeId :: of:: <crate :: uri_resolver:: HttpUri >( ) ; "https" ) ]
273+ #[ test_case( "s3://mybucket/path" , TypeId :: of:: <crate :: uri_resolver:: S3Uri >( ) ; "s3" ) ]
274+ #[ test_case( "secretsmanager://sec" , TypeId :: of:: <crate :: uri_resolver:: SecretsManagerUri >( ) ; "secrets" ) ]
275+ #[ test_case( "ssm://param" , TypeId :: of:: <crate :: uri_resolver:: SsmUri >( ) ; "ssm" ) ]
276+
277+ fn resolver_selection ( input : & str , expected : std:: any:: TypeId ) {
278+ let settings = SettingsInput :: new ( input) ;
279+ let resolver = select_resolver ( & settings) . expect ( "should have a resolver for this scheme" ) ;
280+ let any = resolver. as_ref ( ) as & dyn Any ;
281+ assert_eq ! ( any. type_id( ) , expected) ;
282+ }
283+ }
0 commit comments