Skip to content

Microcks CLI

Simple CLI for interacting with Microcks server APIs. It allows launching tests or import API artifacts with minimal dependencies.

GitHub Workflow StatusContainerLicenseProject ChatArtifact HUBCNCF Landscape

Build Status

Latest release is 1.0.2.

Current development version is 1.0.3. It is available as a container image named quay.io/microcks/microcks-cli:nightly.

Fossa license and security scans

FOSSA StatusFOSSA StatusFOSSA Status

Signature, Provenance, SBOM

Static Badge

OpenSSF best practices on Microcks core

CII Best PracticesOpenSSF Scorecard

Community

To get involved with our community, please make sure you are familiar with the project's Code of Conduct.

Installation

Visit the Release page, browse the Assets and download the one matching your platform

OR you can use the Homebrew package manager on Linux and MacOS that way:

brew tap microcks/tap
brew install microcks/tap/microcks

Usage instructions

Usage

microcks [command] [flags]

Available Commands

CommandDescriptionDocumentation
loginLog in to a Microcks instance using Keycloak credentialslogin
logoutLog out and remove authentication from a given contextlogout
contextManage CLI contexts (list, use, delete)context
startStart a local Microcks instance via Docker/Podmanstart
stopStop a local Microcks instancestop
importImport API spec files from local filesystemimport
import-dirScan a directory and import API spec files.import-dir
import-urlImport API spec files directly from a remote URLimport-url
testRun tests against a deployed API using selected runnertest
versionPrint Microcks CLI versionversion

Options

FlagDescription
-h, --helphelp for microcks command
--configPath to Microcks config file
--microcks-contextName of the Microcks context to use
--verboseProduce dumps of HTTP exchanges
--insecure-tlsAllow insecure HTTPS connections
--caCertsComma-separated paths of CA cert files
--keycloakClientIdKeycloak Realm Service Account ClientId
--keycloakClientSecretKeycloak Realm Service Account ClientSecret
--microcksURLMicrocks API URL

Exit codes

microcks returns a distinct exit code per outcome, so CI can branch on why a run failed — for example retry a flaky runner but fail the build on a broken contract:

CodeMeaning
0Success, or the contract test conformed
1Contract test failed — a clean run whose result did not conform
2Usage — bad arguments or flags
11Connection — could not reach the Microcks or Keycloak endpoint
12API — a server rejected the request or returned an unusable response
13Not found — a requested resource does not exist
14Environment — a local precondition failed (container runtime, image, readiness)
20Generic — an unclassified failure

1 means the tool ran fine and the API violated its contract — not that the tool errored. Codes 0/1/2 follow the common Unix exit-status convention; 1120 are Microcks-CLI–specific. See documentation/error-handling.md.

Local contract testing without a server

microcks test --dry-run runs a contract test with zero infrastructure: no running Microcks server, no Keycloak credentials, no upfront import. The CLI spins up an ephemeral Microcks container (via Testcontainers), imports your spec, runs the test against your endpoint, prints the result and tears the container down.

# One-shot: run once, tear down, exit (exit code 0/1 reflects the test result)
microcks test --dry-run \
--artifact ./openapi.yaml \
"Pastry API:1.0.0" \
http://localhost:3000 \
OPEN_API_SCHEMA
# Watch mode: keep the container alive, re-import + re-run on every save (TDD loop)
microcks test --dry-run --watch \
--artifact ./openapi.yaml \
"Pastry API:1.0.0" \
http://localhost:3000 \
OPEN_API_SCHEMA
FlagDefaultDescription
--dry-runfalseActivate the ephemeral-container path
--artifact(required with --dry-run)Local spec file imported as main artifact
--imagequay.io/microcks/microcks-uber:latest-nativeUber image override (must be a *-native tag)
--ready-timeout90sHow long to wait for the container to be ready
--watchfalseRe-run the test when the artifact file changes

Notes:

  • A localhost/127.0.0.1 test endpoint is automatically reachable from inside the container — the CLI exposes the port and rewrites the endpoint for you.
  • The container is removed on every exit path, including Ctrl+C mid-test.
  • Docker is the primary runtime; Podman works through its Docker-compatible socket (DOCKER_HOST).

Building from Source

To build the CLI locally:

make build-local

The resulting binary will be available at:

/build/dist/microcks

You can move it to a location in your $PATH for global usage, for example:

sudo mv build/dist/microcks /usr/local/bin/microcks

Binary

Binary releases for Linux, MacOS or Windows platform are available on the GitHub releases page. Just download the binary corresponding to your system and put the binary into the PATH somewhere ;-)

Container image

The microcks-cli is available as a container image. So that you'd be able to easily use it from a GitLab CI or a Tekton pipeline. The hosting repository is on Quay.io here.

Below a sample on how to use the image without getting the CLI binary:

$ docker run -it quay.io/microcks/microcks-cli:latest microcks test 'Beer Catalog API:0.9' http://beer-catalog-impl-beer-catalog-dev.apps.144.76.24.92.nip.io/api/ POSTMAN --microcksURL=http://microcks.apps.144.76.24.92.nip.io/api/ --keycloakClientId=microcks-serviceaccount --keycloakClientSecret=7deb71e8-8c80-4376-95ad-00a399ee3ca1 --waitFor=8sec --operationsHeaders='{"globals": [{"name": "x-api-key", "values": "my-values"}], "GET /beer": [{"name": "x-trace-id", "values": "xcvbnsdfghjklm"}]}'

Tekton tasks

This repository also contains different Tekton tasks definitions and sample pipelines. You'll find under the /tekton folder the resource for current v1beta1 Tekton API version and the older v1alpha1 under tekton/v1alpha1.

About

Simple CLI for interacting with Microcks test APIs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

49 stars

Watchers

6 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages