HTTP Server mocking for Go

CI codecov Go Report Card License

This library is used to mock Golang HTTP Server requests for unit tests.

Go package usage

import (
	"net/http"
	"testing"

	mock "github.com/mockingio/mock"
)

func Test_Example(t *testing.T) {
	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)
}

func Test_Example_WithRules(t *testing.T) {
	srv, _ := mock.
		New().
		Get("/hello").
		When("cookie", "name", "equal", "Chocolate").
		Response(http.StatusOK, "hello world").
		Start()
	defer srv.Close()

	req, _ := http.NewRequest("GET", srv.URL, nil)
	client := &http.Client{}

	resp, err := client.Do(req)
}

GitHub

View Github