Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trycmd: allow access to environment variables within a trycmd command-line #365

Open
sebhoss opened this issue Sep 16, 2024 · 3 comments
Open
Labels
A-trycmd Area: trycmd package enhancement Improve the expected

Comments

@sebhoss
Copy link

sebhoss commented Sep 16, 2024

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?

@epage epage added enhancement Improve the expected A-trycmd Area: trycmd package labels Sep 16, 2024
@epage
Copy link
Contributor

epage commented Sep 16, 2024

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?

@sebhoss
Copy link
Author

sebhoss commented Sep 17, 2024

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

@epage epage changed the title trycmd: allow to set substitutable variables trycmd: allow access to environment variables within a trycmd command-line Sep 17, 2024
@epage
Copy link
Contributor

epage commented Sep 17, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trycmd Area: trycmd package enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

2 participants