From fddc64f0dde5c786d7d5766cbc6a16ea8ea08471 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Fri, 1 Dec 2023 18:00:05 -0500 Subject: [PATCH] migrate param bool rules tests off of trycmd --- .../parameters/parameter_rules_bool.md | 59 --------------- tests/test_parameters.rs | 73 ++++++++++++++++--- 2 files changed, 62 insertions(+), 70 deletions(-) delete mode 100644 tests/snapshot-tests/parameters/parameter_rules_bool.md diff --git a/tests/snapshot-tests/parameters/parameter_rules_bool.md b/tests/snapshot-tests/parameters/parameter_rules_bool.md deleted file mode 100644 index d45e9a63..00000000 --- a/tests/snapshot-tests/parameters/parameter_rules_bool.md +++ /dev/null @@ -1,59 +0,0 @@ -# test_parameter_rules_bool - -create a basic parameter without a value, so the rule cannot be violated - -```console -$ cloudtruth param set "param1" --value "true" --type "boolean" -Set parameter 'param1' in project '[PROJECT]' for environment '[ENV]'. - -$ cloudtruth param unset "param1" -Removed parameter value 'param1' from project '[PROJECT]' for environment '[ENV]'. - -``` - -see no rules - -```console -$ cloudtruth param ls --rules -f csv -v -No parameter rules found in project [PROJECT] - -``` - -negative tests for bad rule types: --max, --min, --max-len, --min-len, --regex - -```console -$ cloudtruth param set param1 --max 100 --min 10 --max-len -10 --min-len -1 --regex "abc.*" -? 12 -Rule create error: max rules not valid for boolean parameters -Rule create error: min rules not valid for boolean parameters -Rule create error: max-len rules not valid for boolean parameters -Rule create error: min-len rules not valid for boolean parameters -Rule create error: regex rules not valid for boolean parameters - -$ cloudtruth param set param1 --min-len 10 -? 12 -Rule create error: min-len rules not valid for boolean parameters - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,-,,boolean,0,internal,false, - -$ cloudtruth param ls --rules -f csv -v -No parameter rules found in project [PROJECT] - -``` - -see we don't leave any parameter behind when creating a parameter with an invalid rule - -```console -$ cloudtruth param delete -y "param1" -Removed parameter 'param1' from project '[PROJECT]'. - -$ cloudtruth param set param1 --type boolean --value true --max 10 -? 12 -Rule create error: max rules not valid for boolean parameters - -$ cloudtruth param ls -v -f csv -No parameters found in project [PROJECT] - -``` diff --git a/tests/test_parameters.rs b/tests/test_parameters.rs index 922a9078..e999e452 100644 --- a/tests/test_parameters.rs +++ b/tests/test_parameters.rs @@ -879,18 +879,69 @@ fn test_parameters_over_specified() { } #[test] -fn test_parameters_rules_bool() -> Result<()> { +#[use_harness] +fn test_parameters_rules_bool() { let proj = Project::with_prefix("param-rules-bool").create(); - let env = Environment::with_prefix("param-rules-bool").create(); - trycmd::TestCases::new() - .case("tests/snapshot-tests/parameters/parameter_rules_bool.md") - .register_bin("cloudtruth", cli_bin_path!()) - .env("NO_COLOR", "1") - .env(CT_PROJECT, proj.to_name()) - .env(CT_ENVIRONMENT, env.to_name()) - .insert_var("[PROJECT]", proj.to_name())? - .insert_var("[ENV]", env.to_name())?; - Ok(()) + let envs = hashmap! { + CT_PROJECT => proj.name() + }; + cloudtruth!("param set param1 --value true --type boolean") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param unset param1") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls --rules -f csv -v") + .envs(&envs) + .assert() + .success() + .stdout(contains!("No parameter rules found in project {proj}")); + cloudtruth!("param set param1 --max 100 --min 10 --max-len -10 --min-len -1 --regex 'abc.*'") + .envs(&envs) + .assert() + .failure() + .stderr(contains_all!( + "Rule create error: max rules not valid for boolean parameters", + "Rule create error: min rules not valid for boolean parameters", + "Rule create error: max-len rules not valid for boolean parameters", + "Rule create error: min-len rules not valid for boolean parameters", + "Rule create error: regex rules not valid for boolean parameters", + )); + cloudtruth!("param set param1 --min-len 10") + .envs(&envs) + .assert() + .failure() + .stderr(contains( + "Rule create error: min-len rules not valid for boolean parameters", + )); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param1,-,,boolean,0,internal,false,")); + cloudtruth!("param ls --rules -f csv -v") + .envs(&envs) + .assert() + .success() + .stdout(contains!("No parameter rules found in project {proj}")); + cloudtruth!("param delete -y param1") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param set param1 --type boolean --value true --max 10") + .envs(&envs) + .assert() + .failure() + .stderr(contains( + "Rule create error: max rules not valid for boolean parameters", + )); + cloudtruth!("param ls --rules -f csv -v") + .envs(&envs) + .assert() + .success() + .stdout(contains!("No parameter rules found in project {proj}")); } #[test]