gosttest

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestLogger added in v0.6.0

func NewTestLogger(t testing.TB) *slog.Logger

Types

type EchoHandler

type EchoHandler struct {
	// Requests contains all HTTP requests sent to the handler
	Requests []*http.Request
}

EchoHandler is an http.Handler that echos the requested path in the document heading, i.e., the <h1> element.

func (*EchoHandler) RequestCount

func (h *EchoHandler) RequestCount() int

RequestCount returns how many HTTP requests have been made to the handler

func (*EchoHandler) ServeHTTP

func (h *EchoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GomegaSuite

type GomegaSuite struct {
	suite.Suite
}

GomegaSuite is a specialised suite.Suite that provides support for the gomega assertion library by providing a GomegaSuite.Expect function automatically initializes gomega with

func (*GomegaSuite) Expect

func (s *GomegaSuite) Expect(actual interface{}, extra ...interface{}) types.Assertion

Expect is wraps gomega/Gomega.Expect, passing the correct testing/T. This supports gomega matchers for verification; which can in some cases provide more expressive tests.

type HTTPRequestRecorder added in v0.6.0

type HTTPRequestRecorder struct {
	T        testing.TB
	Handler  http.Handler
	Requests []*http.Request
}

HTTPRequestRecorder is an HTTPHandler middleware that keeps a record of all incoming request objects.

func NewHTTPRequestRecorder added in v0.6.0

func NewHTTPRequestRecorder(t testing.TB, handler http.Handler) *HTTPRequestRecorder

func (*HTTPRequestRecorder) Clear added in v0.6.0

func (r *HTTPRequestRecorder) Clear()

Clear deletes all recorded Requests.

func (*HTTPRequestRecorder) ServeHTTP added in v0.6.0

func (rec *HTTPRequestRecorder) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HTTPRequestRecorder) Single added in v0.6.0

func (r *HTTPRequestRecorder) Single() *http.Request

func (HTTPRequestRecorder) URLs added in v0.6.0

func (r HTTPRequestRecorder) URLs() []string

URLs return all URL strings recorded

type LogRecorder added in v0.6.0

type LogRecorder struct {
	Records []slog.Record
}

LogRecorder is an implementation of slog.Handler recording all log entries in a slice.

func (*LogRecorder) Enabled added in v0.6.0

func (r *LogRecorder) Enabled(context.Context, slog.Level) bool

func (*LogRecorder) FilterLevel added in v0.6.0

func (r *LogRecorder) FilterLevel(lvl slog.Level) (ret []slog.Record)

FilterLevel returns a slice of log records with the specified log level

func (*LogRecorder) Handle added in v0.6.0

func (r *LogRecorder) Handle(_ context.Context, rec slog.Record) error

func (*LogRecorder) Reset added in v0.6.0

func (r *LogRecorder) Reset()

func (*LogRecorder) WithAttrs added in v0.6.0

func (r *LogRecorder) WithAttrs(attrs []slog.Attr) slog.Handler

func (*LogRecorder) WithGroup added in v0.6.0

func (r *LogRecorder) WithGroup(name string) slog.Handler

type StaticFile added in v0.6.0

type StaticFile struct {
	MIMEType string
	Body     string
}

A simple http.Handler that serves static file content. This type is a pair of MIMEType and body content.

func StaticHTML added in v0.6.0

func StaticHTML(html string) StaticFile

StaticHTML creates an http.Handler that serves static content with the MIME type, "text/html".

func StaticJS added in v0.6.0

func StaticJS(js string) StaticFile

StaticJS creates an http.Handler that serves static content with the MIME type, "text/javascript".

func (StaticFile) ServeHTTP added in v0.6.0

func (f StaticFile) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StaticFileServer added in v0.6.0

type StaticFileServer map[string]StaticFile

StaticFileServer is a simple http.Handler that can simplify test code that only needs to configure static files.

As it has a map as an underlying type, you can create the entire http handler as a Go map literal, making it simpler to configure than creating a new mux.

func (StaticFileServer) ServeHTTP added in v0.6.0

func (s StaticFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TestingLogHandler added in v0.6.0

type TestingLogHandler struct {
	testing.TB
	// contains filtered or unexported fields
}

func (TestingLogHandler) Enabled added in v0.6.0

func (l TestingLogHandler) Enabled(_ context.Context, lvl slog.Level) bool

func (TestingLogHandler) Handle added in v0.6.0

func (TestingLogHandler) WithAttrs added in v0.6.0

func (l TestingLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (TestingLogHandler) WithGroup added in v0.6.0

func (l TestingLogHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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