8000 GitHub - flrossetto/gripmock: gRPC Mock Server
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

flrossetto/gripmock

 
 

Repository files navigation

GripMock

Coverage Status

GripMock

GripMock is a mock server for gRPC services. It's using a .proto file or compiled .pb descriptor to generate implementation of gRPC service for you. You can use gripmock for setting up end-to-end testing or as a dummy server in a software development phase. The server implementation is in GoLang but the client can be any programming language that support gRPC.

[Documentation]

This service is a fork of the service tokopedia/gripmock, but you should choose our fork. And here are the reasons:

UI

gripmock-ui

Useful articles

Quick Usage

If you have a simple service, you likely only need a single .proto file to start the GripMock server. However, for more complex projects, you can use the --imports flag to include additional proto files. This approach can become cumbersome, so the recommended solution is to compile a .pb (Protocol Buffers descriptor) file.

Installation

GripMock can be installed using one of the following methods:

1. Using Homebrew (macOS/Linux Recommended)

Homebrew provides an easy way to install GripMock on macOS and Linux.

Step 1: Tap the Repository

Tap the official Homebrew tap for GripMock:

brew tap gripmock/tap

Step 2: Install GripMock

Install GripMock with the following command:

brew install gripmock

Step 3: Verify Installation

Verify that GripMock is installed correctly by checking its version:

gripmock --version

You should see output similar to:

gripmock version v3.2.4

2. Using Shell Script (curl)

For Unix-based systems (Linux/macOS) on arm64/amd64 architectures:

curl -s https://raw.githubusercontent.com/bavix/gripmock/refs/heads/master/setup.sh | sh -s

Example installation output:

ℹ Starting GripMock installation... 🚀
ℹ Checking dependencies...
✔ Dependencies are ready.
ℹ Detecting system information...
✔ Detected OS: linux 🌍
✔ Detected architecture: amd64 💻
ℹ Fetching the latest version of GripMock from GitHub...
✔ Latest version: 3.2.8 🎉
ℹ Downloading checksums file...
✔ Checksums file downloaded.
ℹ Downloading GripMock for linux/amd64...
✔ Downloaded GripMock (9.59 MB)
✔ Checksum verified successfully.
ℹ Installing GripMock...
✔ GripMock has been successfully installed.
ℹ You can now run 'gripmock --help' to get started.
✔ Installation complete! You're all set to use GripMock 🎉

This script automatically:

  1. Detects your OS (Linux/macOS) and architecture (arm64/amd64)
  2. Verifies system dependencies
  3. Downloads the latest release securely
  4. Validates checksums
  5. Installs to your system PATH

3. Download Pre-built Binaries

Pre-built binaries for various platforms are available on the Releases page. Download the appropriate binary for your system and add it to your PATH.

4. Using Docker

GripMock is also available as a Docker image. Pull the latest image with:

docker pull bavix/gripmock

5. Using Go

If you have Go installed, you can install GripMock directly:

go install github.com/bavix/gripmock/v3@latest

Compiling .pb Files (Optional)

Example using protoc:

protoc --proto_path=. --descriptor_set_out=service.pb --include_imports hello.proto

Example using buf:

buf build -o service.pb

Usage

With Gripmock Installed Locally

Start with a .pb or .proto file:

gripmock service.pb
# or
gripmock service.proto

Use a folder containing multiple .proto files:

gripmock protofolder/

Static Stubs (provide mock responses):

# For a folder of proto files
gripmock --stub stubfolder/ protofolder/
# For a single proto file
gripmock --stub stubfolder/ service.proto
# For a pre-compiled .pb file
gripmock --stub stubfolder/ service.pb

With Docker

Folder of proto files:

docker run -p 4770:4770 -p 4771:4771 \
  -v stubfolder:/stubs \
  -v /protofolder:/proto \
  bavix/gripmock /proto/

Single proto file:

docker run -p 4770:4770 -p 4771:4771 \
  -v stubfolder:/stubs \
  -v /protofolder:/proto \
  bavix/gripmock /proto/service.proto

Pre-compiled .pb file:

docker run -p 4770:4770 -p 4771:4771 \
  -v stubfolder:/stubs \
  -v /protofolder:/proto \
  bavix/gripmock /proto/service.pb
  • 4770: gRPC port for mock server
  • 4771: HTTP port for web UI and REST API

Check examples folder for various usecase of GripMock.

How It Works