Skip to content

Commit 018cef9

Browse files
author
Anish Cheraku
committed
address code review feedback 2
1 parent 3df1cb9 commit 018cef9

File tree

5 files changed

+257
-90
lines changed

5 files changed

+257
-90
lines changed

sources/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/api/apiclient/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ serde_json.workspace = true
4444
signal-hook.workspace = true
4545
simplelog.workspace = true
4646
snafu = { workspace = true, features = ["futures"] }
47-
test-case = "*"
47+
test-case.workspace = true
4848
tokio = { workspace = true, features = ["fs", "io-std", "io-util", "macros", "rt-multi-thread", "time"] }
4949
tokio-tungstenite = { workspace = true, features = ["connect"] }
5050
toml.workspace = true
5151
unindent.workspace = true
5252
url.workspace = true
5353
aws-smithy-runtime-api.workspace = true
54+
tempfile.workspace = true
5455

5556
[build-dependencies]
5657
generate-readme.workspace = true

sources/api/apiclient/src/apply.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
261259
pub use error::Error;
262260
pub 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

Comments
 (0)