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

mockingio/go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8fca413 · Aug 3, 2022

History

11 Commits
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022
Aug 3, 2022

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