Comments (14)
Out of the box you can stub crontab and match it against arguments. I don't currently have a feature to capture stdin of a script that has been mocked. Let me see what might be possible.
from bash_shell_mock.
Sorry, but I don't understand what you mean with match it agains arguments
. As far as I can tell, using a pipe is the only programmatic way to update the crontab
from bash_shell_mock.
Currently the shellmock_verify does not provide a way for you to verify the contents of STDIN that was passed into your mock. It only allows you to verify that the command was called and what the arguments were when it was called.
I do not think it would be too difficult to allow you to define a mock that accepts STDIN and then allow you to match the standard input some how in the verify. Correlating the which stdin goes with which mock would be the most challenging part I think.
Does that make sense?
from bash_shell_mock.
Hi and thanks for your answer !
I'll do my best to answer, although I've started to use shellmock
last month : my knowledge of shellmock
internals is still lacking I guess !
So, If I remember correctly, there is an .out
file that shellmock
produces in which the command invocationsgenerated by shellmock_expect
reside.
shellmock_verify
parses this file and gives us an array of lines so that we can match our expectations.
I guess that a mocked command that would accept a value from STDIN would need to be created with an --stdin
flag passed to shellmock_expect
. Wouldn't it result in putting something like echo <value-of--stdin> | mocked-command
in the .out
file ?
Now, I don't see how different stdin values could be mismatched in that scenario
from bash_shell_mock.
I myself have to go back and look at the code to see how i implemented the mocks but that sounds about right. I am going to work on this one today I think. This one is easily solvable particularly if I require a --stdin as you suggested. The only issue is " and ' which is already an issue in shellmock. Because I am doing everything within the shell I am bound by the shell. You can never match quotes unless they were escaped and part of the original string value. Otherwise the shell processes them and my scripting would never see them.
from bash_shell_mock.
This is what the guts of a mock look like.
shellmock_replay is what looks for a matching response. I think the the stdin values should be considered when looking up a response. That way you could return a different response based on different inputs. Currently only args are considered for matching. The matching should include stdin plus the args I think.
#!/bin/bash
export BATS_TEST_DIRNAME="/Users/wut839/workspaces/opensource/bash_shell_mock/sample-bats"
. shellmock
shellmock_capture_cmd grep-stub "$*"
shellmock_replay grep "$*"
status=$?
if [ $status -ne 0 ]; then
shellmock_capture_err $0 failed
exit $status
fi
from bash_shell_mock.
Sounds promising !
from bash_shell_mock.
Can you possibly take a look at this solution to the stdin issue?
I am out of vacation and don't want to push and break stuff, however, the PR is available for review. I updated the readme as well in the shellmock_expect section. I added two new arguments --match-stdin and --stdin-match-type which controls the input data and the rule used to perform the matching.
This PR was built on another PR so it also affects how arguments with spaces in them are matched and verified. You can disable this feature -- assuming i did it right -- by defining SHELLMOCK_V1_COMPATIBILITY.
from bash_shell_mock.
Thanks ! I'll have a look !
from bash_shell_mock.
Hi @ckstettler ! Sorry for the delay about this ! I'm using bash_shell_mock
inside a custom docker image I made with bats
and some bats helper.
I can confirm that I managed to make my existing test suite work with the SHELLMOCK_V1_COMPATIBILITY
flag set ! So you did it right !
But it also means I will have to update all uses of shellmock_expect
to the new way of doing things ! bummer ! 😄
I will try and get the stdin part tested later this week !
from bash_shell_mock.
Non-compatibility is a bummer. It seemed necessary to fix it properly however I am open to any suggestion. Keep in mind if you don't feel that the quote material impacted your tests then you can define the flag globally on and then unset it in new tests and use the new format until a convenient time.
I could create a new expect function or make it a switch in there.
from bash_shell_mock.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from bash_shell_mock.
PR #26 resolves this issue.
from bash_shell_mock.
This enhancement was added as part of release 1.3.
from bash_shell_mock.
Related Issues (13)
- Please add SPDX header to license so license can be identified by automated scanning tools HOT 1
- Regex matching of arguments being passed HOT 5
- Using echo $? returns incorrect status value, from a mock HOT 1
- Contributors agreement HOT 3
- --match string containing double quotes cannot find the given argument HOT 5
- mock custom functions HOT 7
- Mishandling of " contained in mock matches. HOT 4
- Add the use of shellcheck to do some "linting" and make the script better and more transportable HOT 1
- Change file descriptor to stderr if status is greater than 0 HOT 2
- Automate test execution during PRs HOT 5
- Documentation bug. HOT 1
- Bash logo in README HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bash_shell_mock.