- Add `define_cli_auth_test!` macro for authentication-required tests - Add `define_cli_list_test!` macro for unauthenticated list tests - Replace 18 auth tests and 5 list tests with macro invocations - Add `create_entity_cli()` generic, convert per-entity helpers to thin wrappers - Move `create_bag` and `create_gear` from brews_cli.rs to helpers.rs
40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
/// Generates a test that asserts a CLI command fails without authentication.
|
|
macro_rules! define_cli_auth_test {
|
|
($name:ident, $args:expr) => {
|
|
#[test]
|
|
fn $name() {
|
|
let _ = crate::helpers::server_info();
|
|
let output = crate::helpers::run_brewlog($args, &[]);
|
|
assert!(
|
|
!output.status.success(),
|
|
"{} should require authentication",
|
|
stringify!($name)
|
|
);
|
|
}
|
|
};
|
|
}
|
|
|
|
/// Generates a test that asserts a CLI list command succeeds without
|
|
/// authentication and returns a valid JSON array.
|
|
macro_rules! define_cli_list_test {
|
|
($name:ident, $args:expr) => {
|
|
#[test]
|
|
fn $name() {
|
|
let _ = crate::helpers::server_info();
|
|
let output = crate::helpers::run_brewlog($args, &[]);
|
|
assert!(
|
|
output.status.success(),
|
|
"{} should succeed: {}",
|
|
stringify!($name),
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let items: serde_json::Value =
|
|
serde_json::from_str(&stdout).expect("Should output valid JSON");
|
|
assert!(items.is_array(), "Should return a JSON array");
|
|
}
|
|
};
|
|
}
|
|
|
|
pub(crate) use define_cli_auth_test;
|
|
pub(crate) use define_cli_list_test;
|