fakehttp

package
v0.0.0-...-8bfff4f Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fakehttp provides a HTTP server to serve hard-coded responses for unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(r []HardCodedResponse) *httptest.Server

NewServer returns a new FakeServer with a new web server object.

Types

type FakeServer

type FakeServer struct {
	Responses []HardCodedResponse
}

FakeServer defines a fake HTTP server returning a set of hard-coded responses.

func (*FakeServer) ServeHTTP

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

type HardCodedResponse

type HardCodedResponse struct {
	StatusCode         int    // Optional - HTTP status code eg. http.StatusOK
	RequestEscapedPath string // Optional - if present compare to request URL
	RequestBody        string // Optional - if present compare to request body
	RequestMethod      string // Optional - method, default GET
	Response           []byte // Response to send back to client
}

HardCodedResponse defines a static response from a FakeServer.

Jump to

Keyboard shortcuts

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