capitalone / bash_shell_mock Goto Github PK
View Code? Open in Web Editor NEWA shell script mocking utility/framework for the BASH shell
License: Apache License 2.0
A shell script mocking utility/framework for the BASH shell
License: Apache License 2.0
Though there's fairly extensive testing of bashshellmock.sh, there is currently nothing running these in an automated fashion on our PRs. Given it may be more trouble than it's worth to integrate our enterprise Jenkins instances to interact with public GitHub, this issue entails evaluating which (hosted) continuous integration platform to use:
function toTest(){
command -e --params
echo $? # here lies the bug, it returns 0, it should have returned 1 as per shellmock
}
Above is the function to test.
shellmock_expect command --status 1 --match "-e --params"
The easiest example of this is in the sample-bats directory, if you look at the "sample.sh failure" test, modifying the status of the grep command from 1 to 0 does not affect the outcome of the test. This is because shellmock cannot find the grep command to begin with. Easy way to see this is to reverse the if conditional on teardown to see the shellmock error log.
The current workaround that I've been using is to utilize the '--type partial' flag and not look for double quotes in the --match argument.
Hi,
Before I make a PR I was wondering if you would be opposed to having the official Bash logo in the readme?
Here are some examples: https://github.com/odb/official-bash-logo#sightings
Functionality similar to #19 that could not be merged due to a contributor that did not sign the CLA
I propose redirect stdout to stderr if status more than 0, in my humble opinion, this behavior make a sense
@nitinsurana @jdorfman @particleflux @meustrus it seems I had the cart before the horse regarding CapitalOne's opensource contributor policy. All contributors are suppose to complete a CLM prior to me accepting the PR. Obviously that ship has sailed.
I have a PR to add this information within the repo for future contributors. The link is here https://developer.capitalone.com/open-source/
Would you visit the site and read the CLM and if you can agree to it? If so then please submit one. Much of the language is with regard to patent rights which I don't for see being an issue here. I have valued your inputs so far and hope to see your continued use and support. If you can't agree to it I certainly understand.
Please add these lines to the license headers in all the scripts.
SPDX-Copyright: Copyright (c) Capital One Services, LLC
SPDX-License-Identifier: Apache-2.0
node -e "require('./helper').validate()"
Above is how my function call looks. I can't seem to find a corresponding shellmock_expect --match argument. I've tried various combinations like :
shellmock_expect node --status 1 --match '-e "require('./helper').validate()"'
shellmock_expect node --status 1 --match '-e "require(\'./helper\').validate()"'
shellmock_expect node --status 1 --match '-e "require(\"./helper\").validate()"'
throws status 99
The formatting of the readme is not right. The formatting of the table in the shellmock_expect has some sort of syntax issue.
Hi there !
I'm programmatically doing something like echo 0 */2 * * * my_user my_script | crontab -
to add an entry in the current user's crontab.
Can I check that the crontab
really got 0 */2 * * * my_user my_script
from STDIN with bash_shell_mock ?
If I have the following functions file:
functions_file.sh:
docker_user="$1"
docker_password="$2"
docker_registry="$3"
docker login -p ${docker_password} -u ${docker_user} ${registry}
}
main_function(){
helper_function user1 password1 nonexsistent.domain.com
}
And the bats file:
load 'libs/bats-assert/load'
setup() {
. shellmock
source functions_file.sh
skipIfNot "$BATS_TEST_DESCRIPTION"
shellmock_clean
}
teardown() {
if [[ -z "$TEST_FUNCTION" ]]; then
shellmock_clean
fi
}
stub_functions() {
shellmock_expect helper_function --match "user1 password1 registry.domain.com"
}
@test "main" {
stub_functions
run main_function
assert_equal "$status" 0
}
I don't seem to be able to mock the function help_function
When adding some new example test cases:
@test "sample.sh-success-partial-mock" {
shellmock_expect grep --status 0 --output "Mocked output for Partial Match" --type partial --match '"sample line"'
run ./sample.sh
shellmock_dump
[ "$status" = "0" ]
# Validate using lines array.
[ "${lines[0]}" = "Mocked output for Partial Match" ]
# Optionally since this is a single line you can use $output
[ "$output" = "Mocked output for Partial Match" ]
}
This test failed to match even though sample.sh passes this double quoted string as one argument.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.