From 970096b3d47170a007c9e984697b0079f883497e Mon Sep 17 00:00:00 2001 From: softprops Date: Sun, 25 Aug 2019 02:23:48 -0400 Subject: [PATCH] test for is_tag --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8b4fd23..2693c93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,12 +29,16 @@ fn release(conf: &Config) -> Release { } } +fn is_tag(gitref: R) -> bool where R: AsRef { + gitref.as_ref().starts_with("refs/tags/") +} + fn run( conf: Config, releaser: &dyn Releaser, uploader: &dyn AssetUploader, ) -> Result<(), Box> { - if !conf.github_ref.starts_with("refs/tags/") { + if !is_tag(&conf.github_ref) { log::error!("GH Releases require a tag"); return Ok(()); } @@ -81,4 +85,14 @@ mod tests { } Ok(()) } + + #[test] + fn is_tag_checks_refs() { + for (gitref, expect) in &[ + ("refs/tags/foo", true), + ("refs/heads/master", false) + ] { + assert_eq!(is_tag(gitref), *expect) + } + } }