httpmock

package
v2.49.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchAny

func MatchAny(*http.Request) bool

func ReplaceTripper added in v2.14.0

func ReplaceTripper(client *http.Client, reg *Registry)

Replace http.Client transport layer with registry so all requests get recorded.

func RepoNetworkStubResponse

func RepoNetworkStubResponse(owner, repo, defaultBranch, permission string) string

func ScopesResponder

func ScopesResponder(scopes string) func(*http.Request) (*http.Response, error)

Types

type Matcher

type Matcher func(req *http.Request) bool

func GraphQL

func GraphQL(q string) Matcher

func GraphQLMutationMatcher added in v2.28.0

func GraphQLMutationMatcher(q string, cb func(map[string]interface{}) bool) Matcher

func QueryMatcher added in v2.6.0

func QueryMatcher(method string, path string, query url.Values) Matcher

func REST

func REST(method, p string) Matcher

REST returns a matcher to a request for the HTTP method and URL escaped path p. For example, to match a GET request to `/api/v3/repos/octocat/hello-world/` use REST("GET", "api/v3/repos/octocat/hello-world") To match a GET request to `/user` use REST("GET", "user")

type Registry

type Registry struct {
	Requests []*http.Request
	// contains filtered or unexported fields
}

func (*Registry) Register

func (r *Registry) Register(m Matcher, resp Responder)

func (*Registry) RoundTrip

func (r *Registry) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip satisfies http.RoundTripper

func (*Registry) StubRepoInfoResponse

func (r *Registry) StubRepoInfoResponse(owner, repo, branch string)

func (*Registry) StubRepoResponse

func (r *Registry) StubRepoResponse(owner, repo string)

func (*Registry) StubRepoResponseWithPermission

func (r *Registry) StubRepoResponseWithPermission(owner, repo, permission string)

func (*Registry) Verify

func (r *Registry) Verify(t Testing)

type Responder

type Responder func(req *http.Request) (*http.Response, error)

func FileResponse

func FileResponse(filename string) Responder

func GraphQLMutation

func GraphQLMutation(body string, cb func(map[string]interface{})) Responder

func GraphQLQuery

func GraphQLQuery(body string, cb func(string, map[string]interface{})) Responder

func JSONResponse

func JSONResponse(body interface{}) Responder

func RESTPayload

func RESTPayload(responseStatus int, responseBody string, cb func(payload map[string]interface{})) Responder

func StatusJSONResponse added in v2.32.0

func StatusJSONResponse(status int, body interface{}) Responder

func StatusStringResponse

func StatusStringResponse(status int, body string) Responder

func StringResponse

func StringResponse(body string) Responder

func WithHeader added in v2.3.0

func WithHeader(responder Responder, header string, value string) Responder

type Stub

type Stub struct {
	Matcher   Matcher
	Responder Responder
	// contains filtered or unexported fields
}

type Testing

type Testing interface {
	Errorf(string, ...interface{})
	Helper()
}

Jump to

Keyboard shortcuts

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