mockingio / go

Server mocking library for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Server mocking library for Golang


Languages

Language:Go 47.6%Language:Shell 46.3%Language:CUE 6.1%