From 7d18c51238c73d3ce4b34e52d9dda0244c85c3d4 Mon Sep 17 00:00:00 2001 From: softprops Date: Sun, 25 Aug 2019 19:45:44 -0400 Subject: [PATCH] test env parsing --- src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f5a46e8..3d633cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::{ type BoxError = Box; -#[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(()) + } }