SkillAgentSearch skills...

Smock

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.

Install / Use

/learn @MohamedBassem/Smock
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.

View on GitHub
GitHub Stars49
CategoryDevelopment
Updated3y ago
Forks3

Languages

Go

Security Score

60/100

Audited on Jul 15, 2022

No findings