reqtest

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 5 Imported by: 0

README

reqtest

HTTP handlers for testing HTTP requests

Go Reference CI

Usage

package reqtest_test

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/tennashi/reqtest"
)

func TestSomeRequest(t *testing.T) {
	srv := httptest.NewServer(reqtest.CompareMethodHandler(t, "GET"))
	defer srv.Close()

	res, err := http.Get(srv.URL)
	if err != nil {
		t.Fatal(err)
	}
	defer res.Body.Close()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChainHandler

func ChainHandler(handlers ...http.Handler) http.Handler

func CompareHeaderValuesHandler

func CompareHeaderValuesHandler(t *testing.T, key string, values []string) http.Handler

func CompareJSONBodyHandler

func CompareJSONBodyHandler(t *testing.T, params interface{}) http.Handler

func CompareMethodHandler

func CompareMethodHandler(t *testing.T, method string) http.Handler

func ComparePathHandler

func ComparePathHandler(t *testing.T, path string) http.Handler

func CompareQueryHandler added in v0.3.0

func CompareQueryHandler(t *testing.T, want url.Values) http.Handler

Types

type HandlerGenerator

type HandlerGenerator struct {
	OnFailure OnFailure
}

func (*HandlerGenerator) CompareHeaderValues

func (g *HandlerGenerator) CompareHeaderValues(key string, values []string) http.Handler

func (*HandlerGenerator) CompareJSONBody

func (g *HandlerGenerator) CompareJSONBody(jsonBody interface{}) http.Handler

func (*HandlerGenerator) CompareMethod

func (g *HandlerGenerator) CompareMethod(method string) http.Handler

func (*HandlerGenerator) ComparePath

func (g *HandlerGenerator) ComparePath(path string) http.Handler

func (*HandlerGenerator) CompareQuery added in v0.3.0

func (g *HandlerGenerator) CompareQuery(want url.Values) http.Handler

type OnFailure

type OnFailure interface {
	Fail(mes string)
}

type TError

type TError struct {
	// contains filtered or unexported fields
}

func (*TError) Fail

func (n *TError) Fail(mes string)

type TFatal

type TFatal struct {
	// contains filtered or unexported fields
}

func (*TFatal) Fail

func (n *TFatal) Fail(mes string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL