https://github.com/michaelsauter/bock
Bock mocks binaries.
https://github.com/michaelsauter/bock
bash mock
Last synced: 3 months ago
JSON representation
Bock mocks binaries.
- Host: GitHub
- URL: https://github.com/michaelsauter/bock
- Owner: michaelsauter
- Created: 2020-05-25T09:08:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-28T07:23:17.000Z (about 6 years ago)
- Last Synced: 2025-07-20T13:38:09.784Z (12 months ago)
- Topics: bash, mock
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bock mocks binaries.
CAUTION: `bock` is just a proof-of-concept at this stage. It is by no means feature complete or even correct in many cases. Use at your own risk.
Sometimes, one might mock a binary instead of using the real one.
An example use case is mocking `oc`, the CLI binary to interact with OpenShift.
OpenShift is, depending on the host, tricky to install and resource intensive.
Using `bock`, one can mock the interaction to avoid running an actual cluster.
`bock` works by storing the mocked interactions in a temporary file named
`.bock-want` and the actual invocations in a file named `.bock-got`, which can
be compared by calling `mock --verify`.
## Usage
To use `bock`, download `bock.sh` into a folder, but give it the name of the
binary to mock, e.g. `git` or `oc`. Then prepend your `$PATH` with that folder
in your test script. See
https://github.com/michaelsauter/bock/blob/master/tests/run.sh or the following
example:
```
#!/usr/bin/env bash
set -ue
# Download script
curl -L "https://raw.githubusercontent.com/michaelsauter/bock/master/bock.sh" -o oc && chmod +x oc
# Prepend to your path
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PATH=${SCRIPT_DIR}:$PATH
# Check interactions at the end
trap "oc mock --verify" EXIT
# Define interactions
oc mock --receive whoami --stdout "Max Mustermann" --times 1
# Run code that uses "oc" binary ... typically you'd execute your script to test here
oc whoami
```