mockingio


Visit mocking.io for documentation and more information.
Installation
Go install
go install github.com/mockingio/mockingio@latest
Homebrew
brew tap mockingio/mockingio-tap
brew install mockingio/mockingio-tap/mockingio
Docker hub
docker pull mockingio/mockingio
docker run -ti mockingio/mockingio --version
Usage
CLI
# mock.yml
name: Example mock 1
routes:
- method: GET
path: /products
responses:
- body: |
[
{
"id": "1",
"name": "Product 1",
"price": "10.00"
},
{
"id": "2",
"name": "Product 2",
"price": "20.00"
}
]
mockingio start --filename mock.yml
Go package usage
import (
"net/http"
"testing"
mock "github.com/mockingio/mock"
)
func main() {
srv, _ := mock.
New().
Get("/hello").
Response(http.StatusOK, "hello world").
Start()
defer srv.Close()
req, _ := http.NewRequest("GET", srv.URL, nil)
client := &http.Client{}
resp, err := client.Do(req)
// With rules
srv, _ := mock.
New().
Get("/hello").
When("cookie", "name", "equal", "Chocolate").
And("header", "Authorization", "equal", "Bearer 123").
Response(http.StatusOK, "hello world").
Start()
defer srv.Close()
req, _ := http.NewRequest("GET", srv.URL, nil)
client := &http.Client{}
resp, err := client.Do(req)
}