From 604cce91cf759267d1f2b43b6f32262f1d7c2de5 Mon Sep 17 00:00:00 2001 From: Adam Curtis Date: Fri, 1 Dec 2023 18:19:47 -0500 Subject: [PATCH] migrate param types test off of trycmd --- .../parameters/parameter_types.md | 123 ------------------ tests/test_parameters.rs | 98 ++++++++++++-- 2 files changed, 90 insertions(+), 131 deletions(-) delete mode 100644 tests/snapshot-tests/parameters/parameter_types.md diff --git a/tests/snapshot-tests/parameters/parameter_types.md b/tests/snapshot-tests/parameters/parameter_types.md deleted file mode 100644 index 1205330a..00000000 --- a/tests/snapshot-tests/parameters/parameter_types.md +++ /dev/null @@ -1,123 +0,0 @@ - -# test_parameter_types - -boolean tests - -```console -$ cloudtruth param set param1 -t boolean -v true -Set parameter 'param1' in project '[PROJECT]' for environment 'default'. - -``` - -see it in the display - -```console -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, - -``` - -try to set value to non-bool value - -```console -$ cloudtruth param set param1 -v not-a-bool -? 1 -Error: - 0: Rule violation: Value is not of type boolean -... -``` - -change the type back to string - -```console -$ cloudtruth param set "param1" --value "true" --type "string" -Updated parameter 'param1' in project '[PROJECT]' for environment 'default'. - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,string,0,internal,false, - -``` - -update back to bool - -```console -$ cloudtruth param set "param1" --value "true" --type "boolean" -Updated parameter 'param1' in project '[PROJECT]' for environment 'default'. - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, - -``` - -integer tests - -```console -$ cloudtruth param set param2 -t integer -v -1234 -Set parameter 'param2' in project '[PROJECT]' for environment 'default'. - -``` - -see it in the display - -```console -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, -param2,-1234,default,integer,0,internal,false, - -``` - -try to set value to non-integer value - -```console -$ cloudtruth param set param2 -v not-an-integer -? 1 -Error: - 0: Rule violation: Value is not of type integer -... -``` - -change the type back to string - -```console -$ cloudtruth param set "param2" --value "-1234" --type "string" -Updated parameter 'param2' in project '[PROJECT]' for environment 'default'. - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, -param2,-1234,default,string,0,internal,false, - -``` - -update back to integer - -```console -$ cloudtruth param set "param2" --value "-1234" --type "integer" -Updated parameter 'param2' in project '[PROJECT]' for environment 'default'. - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, -param2,-1234,default,integer,0,internal,false, - -``` - -NOTE: no real need to test 'string' types, since that is the default and no illegal values - -```console -$ cloudtruth param set param3 --type foo -? 1 -Error: - 0: Not Found (404): No ParameterType matches the given query. -... - -$ cloudtruth param ls -v -f csv -Name,Value,Source,Param Type,Rules,Type,Secret,Description -param1,true,default,boolean,0,internal,false, -param2,-1234,default,integer,0,internal,false, - -``` diff --git a/tests/test_parameters.rs b/tests/test_parameters.rs index e999e452..0baa893d 100644 --- a/tests/test_parameters.rs +++ b/tests/test_parameters.rs @@ -1408,15 +1408,97 @@ fn test_parameters_table_formats() { } #[test] -fn test_parameters_types() -> Result<()> { +#[use_harness] +fn test_parameters_types() { let proj = Project::with_prefix("param-types").create(); - trycmd::TestCases::new() - .case("tests/snapshot-tests/parameters/parameter_types.md") - .register_bin("cloudtruth", cli_bin_path!()) - .env("NO_COLOR", "1") - .env(CT_PROJECT, proj.to_name()) - .insert_var("[PROJECT]", proj.to_name())?; - Ok(()) + let envs = hashmap! { + CT_PROJECT => proj.name() + }; + // boolean tests + cloudtruth!("param set param1 -t boolean -v true") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param1,true,default,boolean,0,internal,false,")); + // try to set to non-bool value + cloudtruth!("param set param1 -v not-a-bool") + .envs(&envs) + .assert() + .failure() + .stderr(contains("Rule violation: Value is not of type boolean")); + // change type to string + cloudtruth!("param set param1 --value true --type string") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param1,true,default,string,0,internal,false,")); + // change type back to bool + cloudtruth!("param set param1 --value true --type boolean") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param1,true,default,boolean,0,internal,false,")); + // integer tests + cloudtruth!("param set param2 -t integer -v -1234") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param2,-1234,default,integer,0,internal,false,")); + // try to set to non-bool value + cloudtruth!("param set param2 -v not-an-integer") + .envs(&envs) + .assert() + .failure() + .stderr(contains("Rule violation: Value is not of type integer")); + // change the type to string + cloudtruth!("param set param2 --value '-1234' --type string") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param2,-1234,default,string,0,internal,false,")); + // change the type back to integer + cloudtruth!("param set param2 --value '-1234' --type integer") + .envs(&envs) + .assert() + .success(); + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(contains("param2,-1234,default,integer,0,internal,false,")); + // NOTE: no need for string tests, since this is the default + // try to set invalid type + cloudtruth!("param set param3 --type foo") + .envs(&envs) + .assert() + .failure() + .stderr(contains("No ParameterType matches the given query.")); + // verify invalid param was not created + cloudtruth!("param ls -v -f csv") + .envs(&envs) + .assert() + .success() + .stdout(not(contains("param3"))); } #[test]