I’m considerably newbie to Bats and using shellmock to mock the behaviour, I have below query. Thanks in Advance.
if [[ "$create_commit_status" = true ]]; then
echo "Vulnerable Found"
if [[ -f /helper.py ]]; then
python3 /helper.py
create-commit-status
--git-token "$GITHUB_TOKEN"
--git-user "$GIT_USER"
--git-org "$GIT_ORG"
--git-repo "$GIT_REPO"
--commit-sha "$COMMIT_SHA"
--commit-state "$COMMIT_STATE"
--commit-context "$COMMIT_CONTEXT"
--description "$DESCRIPTION"
--build-url "$BUILD_URL"
--api-base-url "$API_URL"
else
echo "Error: /helper.py not found."
exit 1 # Fail the script with an error status
fi
fi
so this is in a bash script call one.sh
and I have written a bats test call one.bats as
setup_file() {
# Mock environment variables required by the commit status script
export BUILD_URL="mock_build_url"
export GIT_URL="Testing"
export GITHUB_TOKEN="test"
export GIT_USER="test"
export GIT_ORG="test"
export GIT_REPO="test"
export COMMIT_SHA="test"
export COMMIT_STATE="test"
export COMMIT_CONTEXT="test"
export DESCRIPTION="test"
export API_URL="test"
}
setup() {
load bats related libraries
}
@test "Search jars" {
shellmock new python3
shellmock config python3 0 1:"create-commit-status --git-token ${GITHUB_TOKEN} --git-user ${GIT_USER} --git-org ${GIT_ORG} --git-repo ${GIT_REPO} --commit-sha ${COMMIT_SHA} --commit-state ${COMMIT_STATE} --commit-context ${COMMIT_CONTEXT} --description ${DESCRIPTION} --build-url ${BUILD_URL} --api-base-url ${API_URL}"
o:"Commit status successfully created"
run bash -c "source one.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Searching for jars" ]]
[[ "$output" == *"Commit status successfully created"* ]]
}
Now this is not working with and error is
Incorrect format of argspec: o:Commit status successfully created
Does anyone know how to do it? What’s the issue? The sources over internet are clumsy.
Can anyone help me?
0