Skip to content

Commit f93791f

Browse files
migrate parameter export test off of trycmd (#585)
1 parent efae89b commit f93791f

File tree

2 files changed

+129
-144
lines changed

2 files changed

+129
-144
lines changed

tests/snapshot-tests/parameters/parameter_export.md

Lines changed: 0 additions & 136 deletions
This file was deleted.

tests/test_parameters.rs

Lines changed: 129 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,136 @@ fn test_parameters_copy() {
445445
}
446446

447447
#[test]
448-
fn test_parameters_export() -> Result<()> {
448+
#[use_harness]
449+
fn test_parameters_export() {
449450
let proj = Project::with_prefix("param-export").create();
450-
trycmd::TestCases::new()
451-
.case("tests/snapshot-tests/parameters/parameter_export.md")
452-
.register_bin("cloudtruth", cli_bin_path!())
453-
.env("NO_COLOR", "1")
454-
.env(CT_PROJECT, proj.to_name())
455-
.insert_var("[PROJECT]", proj.to_name())?;
456-
Ok(())
451+
let envs = hashmap! {
452+
CT_PROJECT => proj.name()
453+
};
454+
// make sure there are no parameters at start
455+
cloudtruth!("parameters list")
456+
.envs(&envs)
457+
.assert()
458+
.success()
459+
.stdout(contains!("No parameters found in project {proj}"));
460+
// create first param
461+
cloudtruth!("param set first_param --value posix_compliant_value")
462+
.envs(&envs)
463+
.assert()
464+
.success();
465+
// create param with spaces in value
466+
cloudtruth!("param set SECOND_PARAM --value 'a value with spaces'")
467+
.envs(&envs)
468+
.assert()
469+
.success();
470+
// create param with non-posix key
471+
cloudtruth!("param set 'non.posix.key' --value posix_value_invalid_key")
472+
.envs(&envs)
473+
.assert()
474+
.success();
475+
// create secret params
476+
cloudtruth!("param set FIRST_PARAM_SECRET --value 'top-secret-sci' --secret true")
477+
.envs(&envs)
478+
.assert()
479+
.success();
480+
cloudtruth!("param set second_secret --value 'sensitive value with spaces' --secret true")
481+
.envs(&envs)
482+
.assert()
483+
.success();
484+
// docker export
485+
cloudtruth!("param export docker")
486+
.envs(&envs)
487+
.assert()
488+
.success()
489+
.stdout(diff("*****\n"));
490+
cloudtruth!("param export docker --secrets")
491+
.envs(&envs)
492+
.assert()
493+
.success()
494+
.stdout(diff(indoc! {"
495+
FIRST_PARAM=posix_compliant_value
496+
FIRST_PARAM_SECRET=top-secret-sci
497+
SECOND_PARAM=a value with spaces
498+
SECOND_SECRET=sensitive value with spaces
499+
500+
"}));
501+
// --starts-with option
502+
cloudtruth!("param export docker --secrets --starts-with SECOND")
503+
.envs(&envs)
504+
.assert()
505+
.success()
506+
.stdout(diff(indoc! {"
507+
SECOND_PARAM=a value with spaces
508+
SECOND_SECRET=sensitive value with spaces
509+
510+
"}));
511+
// filter without secrets
512+
cloudtruth!("param export docker --starts-with FIRST")
513+
.envs(&envs)
514+
.assert()
515+
.success()
516+
.stdout(diff("*****\n"));
517+
// filter with secrets
518+
cloudtruth!("param export docker --secrets --starts-with FIRST")
519+
.envs(&envs)
520+
.assert()
521+
.success()
522+
.stdout(diff(indoc! {"
523+
FIRST_PARAM=posix_compliant_value
524+
FIRST_PARAM_SECRET=top-secret-sci
525+
526+
"}));
527+
// search is case insensitive
528+
cloudtruth!("param export docker --contains param -s")
529+
.envs(&envs)
530+
.assert()
531+
.success()
532+
.stdout(diff(indoc! {"
533+
FIRST_PARAM=posix_compliant_value
534+
FIRST_PARAM_SECRET=top-secret-sci
535+
SECOND_PARAM=a value with spaces
536+
537+
"}));
538+
// see if filter picks up non-posix
539+
cloudtruth!("param export docker --contains posix -s")
540+
.envs(&envs)
541+
.assert()
542+
.success()
543+
.stdout(diff("\n"));
544+
// .env export
545+
cloudtruth!("param export dotenv")
546+
.envs(&envs)
547+
.assert()
548+
.success()
549+
.stdout(diff("*****\n"));
550+
cloudtruth!("param export dotenv -s")
551+
.envs(&envs)
552+
.assert()
553+
.success()
554+
.stdout(diff(indoc! {r#"
555+
FIRST_PARAM="posix_compliant_value"
556+
FIRST_PARAM_SECRET="top-secret-sci"
557+
SECOND_PARAM="a value with spaces"
558+
SECOND_SECRET="sensitive value with spaces"
559+
560+
"#}));
561+
// shell export
562+
cloudtruth!("param export shell")
563+
.envs(&envs)
564+
.assert()
565+
.success()
566+
.stdout(diff("*****\n"));
567+
cloudtruth!("param export shell -s")
568+
.envs(&envs)
569+
.assert()
570+
.success()
571+
.stdout(diff(indoc! {"
572+
FIRST_PARAM=posix_compliant_value
573+
FIRST_PARAM_SECRET=top-secret-sci
574+
SECOND_PARAM='a value with spaces'
575+
SECOND_SECRET='sensitive value with spaces'
576+
577+
"}));
457578
}
458579

459580
#[test]

0 commit comments

Comments
 (0)