Git Product home page Git Product logo

iq-scm / smock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mohamedbassem/smock

0.0 0.0 0.0 20 KB

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.

Home Page: http://blog.mbassem.com/2016/02/09/smock/

Go 100.00%

smock's Introduction

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.

smock's People

Contributors

mohamedbassem avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.