mockingio

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

mockingio

CI codecov Docker Repository Github Release Go Report Card License

asciicast

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)
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
cmd
cli
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL