Skip to content

Mockerize-io/mockerize-cli

Repository files navigation

Version Tests

https://mockerize-io

mockerize-cli

Mockerize is an open-source, cross platform, lightweight, server mocking application designed from the ground up to make creating mock development servers quick and painless.

example running mockerize-cli

Potential use cases

  • Integration testing in your CI/CD pipeline
  • End-to-end test your client-side HTTP code
  • Mock API servers to speed up development

Building

Assuming that you've already cloned the repo and have Rust installed, you have everything you need to build binaries for your operating system:

cargo build --release

You may configure additional build options in Cargo.toml.

Cross-compiling

If you would like to compile for a different operating system than your own, you will first need to install the build target toolchain and cross, the cross-compiling tools for Rust. First use the rustup target list command to see if you already have the target toolchain installed. You may see available targets in the Rust docs.

Install cross if you don't already have it:

cargo install cross

Install the target toolchain:

rustup target add x86_64-unknown-linux-gnu

Cross-compile for target:

cargo build --target=x86_64-unknown-linux-gnu

See also: Cross-compilation - the rustup book

Usage

Before using mockerize-cli, you should create a server config file. This can be done through the Mockerize GUI app, or by creating a JSON file following the Mockerize JSON standard structure. A server config defines the server's listen address & port, as well as any routes and their paired response(s).

You may generate an example server config to build off of with the new command:

mockerize-cli new my-config.json

You should then edit your config file using your editor of choice. When ready, load the config with the run command:

mockerize-cli run ./my-config.json

Then you should be able to hit your mock server:

curl http://127.0.0.1:8080/hello-world

Usage in automated testing

One potential use case for mockerize-cli is while automatically running integration tests; perhaps as part of your CI/CD pipeline.

# Start mockerize in background, load in our test server config.
# Also get the process ID of the mockerize instance so we can kill it later.
./mockerize-cli run integration-test.json >/dev/null 2>&1 &
pid=$!

# Give it some time to fully start up before we begin our tests.
# Please consider your exact use case here. A short rest is probably good enough,
# though may not be the best choice for you. Perhaps add a health-check endpoint
# to your config, then rely on something like `wait-for-it` to inform when the server
# is fully operational and serving traffic
sleep 1

# Run tests, then exit
echo "Running (pretend) integration tests"
# ... cmd to run tests goes here

echo "Done testing. Killing mockerize-cli (PID $pid)"
kill -9 $pid

While the above example is often enough for simple use, you may wish to expand upon it. Do you need to run different server configs per test? Perhaps you may integrate the startup and shutdown of Mockerize within your test runner.

Packages

No packages published

Languages