Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

mockingio/go

Repository files navigation

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