ht

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: ISC Imports: 6 Imported by: 0

Documentation

Overview

Package ht contains HTTP testing utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsJSON

func AsJSON(v any) []byte

AsJSON unmarshals the response body as JSON. It panics if the unmarshaling fails.

Types

type Response

type Response struct {
	Status int
	Body   []byte
}

Response is a minimal HTTP response.

type Server

type Server struct {
	httptest.Server
}

Server is a test server that can be used to test HTTP handlers.

func NewServer

func NewServer(h http.Handler) *Server

NewServer creates a new test server with the given handler.

func (*Server) Close

func (s *Server) Close()

Close closes the server and cleans up any resources.

func (*Server) MustGet

func (s *Server) MustGet(path string, v url.Values) Response

MustGet performs a GET request to the given path with the given query parameters. It panics if the request fails.

func (*Server) MustPost

func (s *Server) MustPost(path, contentType string, body []byte) Response

MustPost performs a POST request to the given path with the given value to be used as a JSON body.

Jump to

Keyboard shortcuts

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