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

Latest commit

 

History

History
48 lines (37 loc) · 1.27 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.27 KB

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