diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9c9850b..87b2816 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: push: tags: # Match semantic version tags (e.g. v1.2.3, v10.11.12, v12.3.7-beta7) - - 'v[0-9]*.[0-9]*.[0-9]*' + - 'v*.*.*' jobs: goreleaser: diff --git a/Cargo.lock b/Cargo.lock index 8e1ec7e..d8b8f94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,6 +324,7 @@ dependencies = [ "cucumber", "octocrab", "ortho_config", + "regex", "serde", "serde_json", "serde_yaml", @@ -349,6 +350,8 @@ dependencies = [ "serde_json", "serial_test", "tempfile", + "test-support", + "test-utils", "thiserror 1.0.69", "tokio", "tracing", @@ -2452,6 +2455,7 @@ version = "0.1.0" dependencies = [ "comenqd", "octocrab", + "serial_test", "tempfile", "tokio", "wiremock", diff --git a/Cargo.toml b/Cargo.toml index 0fdfd2d..deaecef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,11 +18,12 @@ clap = { workspace = true } comenq = { path = "crates/comenq" } comenqd = { path = "crates/comenqd" } ortho_config = { git = "https://github.com/leynos/ortho-config.git", tag = "v0.4.0" } -tempfile = "3.10" # latest 3.x at time of writing; update as new patch versions release +tempfile = { workspace = true } # latest 3.x at time of writing; update as new patch versions release yaque = { workspace = true } -wiremock = "0.6" +wiremock = { workspace = true } octocrab = { workspace = true } test-support = { path = "test-support" } +regex = { workspace = true } [[test]] name = "cucumber" @@ -51,7 +52,9 @@ thiserror = "1.0" ortho_config = { git = "https://github.com/leynos/ortho-config.git", tag = "v0.4.0" } serde_yaml = "0.9" tempfile = "3.10" +regex = "1" rstest = "0.18.0" +wiremock = "0.6" [lints.clippy] pedantic = { level = "warn", priority = -1 } diff --git a/crates/comenqd/Cargo.toml b/crates/comenqd/Cargo.toml index a54dd01..2a93bdf 100644 --- a/crates/comenqd/Cargo.toml +++ b/crates/comenqd/Cargo.toml @@ -23,4 +23,6 @@ figment = { version = "0.10", default-features = false, features = ["env", "toml rstest = { workspace = true } tempfile = { workspace = true } # latest 3.x at time of writing; update as new patch versions release serial_test = "2" -wiremock = "0.6" +test-support = { path = "../../test-support" } +test-utils = { path = "../test-utils" } +wiremock = { workspace = true } diff --git a/crates/comenqd/src/config.rs b/crates/comenqd/src/config.rs index 6f0bb6d..ca9bf29 100644 --- a/crates/comenqd/src/config.rs +++ b/crates/comenqd/src/config.rs @@ -118,53 +118,7 @@ mod tests { use std::fs; use tempfile::tempdir; - mod env_guard { - //! Test helpers for managing environment variables. - - #[derive(Debug)] - pub struct EnvVarGuard { - key: String, - original: Option, - } - - impl EnvVarGuard { - /// Set an environment variable for the lifetime of the returned guard. - pub fn set(key: &str, value: &str) -> Self { - let original = std::env::var(key).ok(); - set_env_var(key, value); - Self { - key: key.to_string(), - original, - } - } - } - - impl Drop for EnvVarGuard { - fn drop(&mut self) { - match &self.original { - Some(v) => set_env_var(&self.key, v), - None => remove_env_var(&self.key), - } - } - } - - /// Set an environment variable for tests. - /// - /// The nightly compiler marks `std::env::set_var` as `unsafe`. - /// Tests run serially so using it is acceptable here. - pub fn set_env_var(key: &str, value: &str) { - unsafe { std::env::set_var(key, value) }; - } - - /// Remove an environment variable for tests. - /// - /// `std::env::remove_var` is also `unsafe` on nightly. - pub fn remove_env_var(key: &str) { - unsafe { std::env::remove_var(key) }; - } - } - - use env_guard::{EnvVarGuard, remove_env_var}; + use test_support::env_guard::{EnvVarGuard, remove_env_var}; #[rstest] #[serial_test::serial] diff --git a/test-support/Cargo.toml b/test-support/Cargo.toml index ac68fa2..f2cab36 100644 --- a/test-support/Cargo.toml +++ b/test-support/Cargo.toml @@ -9,3 +9,6 @@ comenqd = { path = "../crates/comenqd" } octocrab = { workspace = true } tempfile = { workspace = true } wiremock = "^0.6" + +[dev-dependencies] +serial_test = "^2" diff --git a/tests/support/env_guard.rs b/test-support/src/env_guard.rs similarity index 100% rename from tests/support/env_guard.rs rename to test-support/src/env_guard.rs diff --git a/test-support/src/lib.rs b/test-support/src/lib.rs index e879eb7..52cbe23 100644 --- a/test-support/src/lib.rs +++ b/test-support/src/lib.rs @@ -1,10 +1,12 @@ //! Test support utilities. pub mod daemon; +pub mod env_guard; pub mod util; // Re-exports from daemon module (added in main) pub use daemon::{octocrab_for, temp_config}; +pub use env_guard::{EnvVarGuard, remove_env_var, set_env_var}; // Re-exports from util module with documentation (from your branch) /// Maximum number of times to poll for an expected file. diff --git a/tests/cucumber.rs b/tests/cucumber.rs index 5def2b1..b8ca602 100644 --- a/tests/cucumber.rs +++ b/tests/cucumber.rs @@ -4,7 +4,6 @@ //! parallel. mod steps; -mod support; mod util; use cucumber::World as _; use steps::{ diff --git a/tests/steps/config_steps.rs b/tests/steps/config_steps.rs index a03fbab..f6e43bf 100644 --- a/tests/steps/config_steps.rs +++ b/tests/steps/config_steps.rs @@ -5,8 +5,8 @@ use std::fs; use std::path::PathBuf; use tempfile::TempDir; -use crate::support::env_guard::{EnvVarGuard, remove_env_var}; use comenqd::config::Config; +use test_support::env_guard::{EnvVarGuard, remove_env_var}; #[derive(Debug, Default, World)] pub struct ConfigWorld { diff --git a/tests/steps/release_steps.rs b/tests/steps/release_steps.rs index 5726318..d9df276 100644 --- a/tests/steps/release_steps.rs +++ b/tests/steps/release_steps.rs @@ -3,6 +3,7 @@ use comenq_lib::workflow::uses_goreleaser as workflow_uses_goreleaser; use cucumber::{World, given, then, when}; +use regex::Regex; use serde_yaml::Value; use std::fs; @@ -40,8 +41,11 @@ fn triggers_on_tags(world: &mut ReleaseWorld) { .expect("tags") .as_sequence() .expect("sequence"); + let pattern = Regex::new(r"^v\*\.\*\.\*$").expect("compile regex"); assert!( tags.iter() - .any(|t| t.as_str() == Some("v[0-9]*.[0-9]*.[0-9]*")) + .filter_map(|t| t.as_str()) + .any(|t| pattern.is_match(t)), + "missing semantic version tag pattern", ); } diff --git a/tests/support/mod.rs b/tests/support/mod.rs deleted file mode 100644 index 0ab1eed..0000000 --- a/tests/support/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Support utilities shared by tests. - -pub mod env_guard;