Skip to content

dougrich/httptestutil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Golang HTTP Testing Utilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages