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

'unmock' binaries? #6

Open
corps opened this issue Aug 24, 2021 · 1 comment
Open

'unmock' binaries? #6

corps opened this issue Aug 24, 2021 · 1 comment

Comments

@corps
Copy link

corps commented Aug 24, 2021

Really cool project, love the approach and simplicity.

As I understand it, when you run a test, all commands are mocked, including those found on the path, by default.
This is great 99% of the time, but there is a case where I do want the original command to be fully run within the script I am testing.

Here is my situation.
I am testing some docker script automation. I used @mock to mock the docker scripts with fixtures pulled from real execution of docker. Now, I want to test that piping those fixtures from the mocked docker into my script's grep and jq produces the expected results. In this case, I need the script being tested to actually run grep and jq.

I know I can execute @real grep or even @grep within a test, but I cannot wire the script subject I am testing to include @real at the front of all its binary calls. Basically, I want a configurably mixed mode of mocks and real command executions.

I tried creating a function grep and function jq that executes @real grep $@ but this does not seem to work, as the piping of stdin and stdout and processing of args does not work exactly right. @unmock only reverses a mock, it does not seem to make an executable 'available' to be run within the target script.

Is there a technique that can be used to allow scripts being tested to actually execute certain commands using PATH and no mock interactions?

@chaifeng
Copy link
Collaborator

Hi corps, thank you for using Bach Testing Framework.

If you want to check if grep and jq can search and output the results you expect. You can test it manually from command line. And then put the same commands into your script file, they should also work.

If you want to grab the output of jq command, you just need to use @mock api to mock jq command to output the result you expect. You don't need to actually run grep and jq commands.

Just a reminder, that we must explicitly mock all commands in a pipeline command. Otherwise, this test case may be fail due to the random order of these commands. Mock the last command of a pipeline command to get the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants