Skip to content

Smock ( Previously: RequestBin ) is a golang package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

MohamedBassem/Smock

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Smock

Build Status Coverage Status GoDoc

The package was previously called RequestBin, but was changed as per the request of @johnsheehan, the CEO of Runscope (The company behind http://requestb.in/). Clones will still work with the old name thanks to Github, but the API will be slightly changed.

Smock is a package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

Example

func ExampleCaptureRequests() {
	reqs := smock.NewMockServer(smock.MockServerConfig{RequestTimeout: 1}).CaptureRequests(func(url string) {
		http.Post(url, "text/plain", strings.NewReader("Hello"))
		http.Post(url, "text/plain", strings.NewReader("It's me"))
	})

	fmt.Println(reqs[0].Body) // Hello
	fmt.Println(reqs[1].Body) // It's me
}

The server can be stopped after a certain amount of seconds, after a certain amount of requests, whenever it doesn't receive any new requests for a certain amount of time or any combination of the three.

API

The API is very simple and you can check it on GoDoc. Reading the tests is also a good way for understanding the API.

Usecase

For a usecase you can read my blog post about this package : http://blog.mbassem.com/2016/02/09/smock/.

Contribution

Your contributions and ideas are welcomed through issues and pull requests.

About

Smock ( Previously: RequestBin ) is a golang package for testing the outgoing http requests initiated from a function. The package creates a mock server and passes the URL to the function to be tested and then collects all the requests that the server received.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages