mock

package
v0.260.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMockHTTPClient

func GetMockHTTPClient(rt RoundTripper) *http.Client

Types

type RoundTripper

type RoundTripper struct {
	// Response mock
	GetResponse func(req *http.Request) (*http.Response, error)
	HARFileName string // filename (relative path of where it is being called)
	GetFileName func(req *http.Request) string
	FileName    string // filename (relative path of where it is being called)
	GetBody     func(req *http.Request) string
	Body        string
	// Response status and headers
	StatusCode      int
	Status          string
	ResponseHeaders map[string]string
	// Authentication
	BasicAuthEnabled  bool
	BasicAuthUser     string
	BasicAuthPassword string
}

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip provides a http transport method for simulating http response If GetResponse present and return non-nil values, they will be returned. This will be useful to mock authentication errors bases on request headers Else If HARFileName present, it will take priority Else if GetFileName present and return valid file name, it will respond with corresponding file content Else if FileName present, it will read the response from the filename Else if GetBody present and return valid string, it will respond with corresponding string Else if Body present, it will echo the body Else default response {} will be sent

Jump to

Keyboard shortcuts

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