Categorygithub.com/dougrich/httptestutil
repositorypackage
0.0.0-20200311164329-e6e658f9a520
Repository: https://github.com/dougrich/httptestutil.git
Documentation: pkg.go.dev

# README

HTTPTestUtil

Contains shared utilities for running http tests.

You craft a httptestutil.TestSet, or a set of assertions about the behavior of a handler. This consists of multiple httptestutil.TestConfig, which are created using the httptestutil.Test function - this takes a name for the test, and then a series of httptestutil.TestOption which either modify the request or create assertions about the response.

This is most useful for blackbox testing of a handler, where you don't understand the internals.

Simple Example

package main

import (
	"testing"
	"net/http"
	"github.com/dougrich/httptestutil"
)

func TestHandler(t *testing.T) {
	httptestutil.TestSet{
		httptestutil.Test(
			"RejectGET405",
			httptestutil.RequestMethod(http.MethodGet),
			httptestutil.ResponseStatus(http.StatusMethodNotAllowed),
		),
	}.Run(t, &Handler{})
}