trycmd
trycmd copied to clipboard
trycmd: allow access to environment variables within a trycmd command-line
I'm trying to define a variable with contains a random value and want to inject it somehow into tests executed by trycmd. I can mask the value with insert_var(..) and tried to use env(..) to make the variable accessible in my tests but something like $ echo $TEST_VALUE never substitutes the variable with the value given to env(..). Is there some way to access the value behind a variable?
If I'm understanding correctly, you are wanting to access environment variables on the "command-line" as these are inputs that are determined at runtime?
yeah exactly! A simplified code example looks like this:
let key = "some-randomly-generated-value";
trycmd::TestCases::new()
.case("tests/cmd/secrets/*.md")
.env("KEY", key)
.insert_var("[KEY]", key)
.unwrap();
and I want to run a test like this:
$ bin-command secrets add $KEY
key '[KEY]' added
my current workaround is to write the generated value into a file, add that file to gitignore (so that it won't get flagged by security scans..) and allow my add subcommand to read from files
As we have another concept of substitutions (also called redactions) in terms of insert_var, I've clarified the issue name.
This is another part in the overall story thats building up in issues of "it would be nice if we had an embedded shell to work with". We have requests for pipes (#172) and some common unix built-ins (e.g. #168, #43)