Skip to content

Repository files navigation

httpfake

LICENSEGodocsBuild StatusCoverage StatusGo Report Card

httpfake provides is a simple wrapper for httptest with a handful chainable API for setting up handlers to a fake server. This package is aimed to be used in tests where the original external server must not be reached. Instead is used in its place a fake server which can be configured to handle any request as desired.

Installation

go get -u github.com/maxcnunes/httpfake

or

govendor fetch github.com/maxcnunes/httpfake

If possible give preference for using vendor. This way the version is locked up as a dependency in your project.

Changelog

See Releases for detailed history changes.

API

See godoc reference for detailed API documentation.

Examples

For a full list of examples please check out the functional_tests folder.

// initialize the faker server// will bring up a httptest.ServerfakeService:=httpfake.New()
// bring down the server once we// finish running our testsdeferfakeService.Server.Close()
// register a handler for our fake servicefakeService.NewHandler().
Get("/users").
Reply(200).
BodyString(`[{"username": "dreamer"}]`)
// run a real http request to that serverres, err:=http.Get(fakeService.ResolveURL("/users"))

Contributing

See the Contributing guide for steps on how to contribute to this project.

Reference

This package was heavily inspired by gock. Check that you if you prefer mocking your requests.

About

Httpfake – A Golang httptest wrapper for easily setting up a fake server

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages