test env parsing
This commit is contained in:
parent
c7c4aa0f5a
commit
7d18c51238
1 changed files with 26 additions and 1 deletions
27
src/main.rs
27
src/main.rs
|
@ -12,7 +12,7 @@ use std::{
|
|||
|
||||
type BoxError = Box<dyn Error>;
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
#[derive(Deserialize, Default, Debug, PartialEq)]
|
||||
struct Config {
|
||||
// provided
|
||||
github_token: String,
|
||||
|
@ -168,4 +168,29 @@ mod tests {
|
|||
assert_eq!(paths(vec!["tests/data/**/*"])?.into_iter().count(), 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_is_parsed_from_env() -> Result<(), BoxError> {
|
||||
for (env, expect) in vec![(
|
||||
vec![
|
||||
("GITHUB_TOKEN".into(), "123".into()),
|
||||
("GITHUB_REF".into(), "refs/tags/ref".into()),
|
||||
("GITHUB_REPOSITORY".into(), "foo/bar".into()),
|
||||
("INPUT_NAME".into(), "test release".into()),
|
||||
("INPUT_BODY".into(), ":)".into()),
|
||||
("INPUT_FILES".into(), "*.md".into()),
|
||||
],
|
||||
Config {
|
||||
github_token: "123".into(),
|
||||
github_ref: "refs/tags/ref".into(),
|
||||
github_repository: "foo/bar".into(),
|
||||
input_name: Some("test release".into()),
|
||||
input_body: Some(":)".into()),
|
||||
input_files: Some(vec!["*.md".into()])
|
||||
},
|
||||
)] {
|
||||
assert_eq!(expect, envy::from_iter::<_, Config>(env)?)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue