mockery_test

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go Lang Version Go Doc Go Report Card codecov CircleCI

Mockery

Mockery is a go library that enables programmers to create mock http servers for the purpose of testing their integrations in isolation. It is particularly good at doing performance testing since one instance can handle a very large number of tps. I have tested a basic mockery handling 100,000 tps without using more than 20% CPU on an 8 core system.

Getting Started

Here is an example mockery.

package mockery_test

import (
	"log"
	"net/http"
	. "github.com/bluesoftdev/mockery/httpmock"
	. "github.com/bluesoftdev/go-http-matchers/extractor"
	. "github.com/bluesoftdev/go-http-matchers/predicate"
)

func main() {
	mockery := Mockery(func() {
		Endpoint("/foo/bar", func() {
			Method("GET", func() {
				Header("Content-Type", "application/json")
				Header("FOO", "BAR")
				RespondWithFile(500, "./error.json")
				FixedDelay("10ms")
			})
		})
		Endpoint("/foo/bar/", func() {
			Method("GET", func() {
				Header("Content-Type", "application/json")
				Header("FOO", "BAR")
				RespondWithFile(200, "./ok.json")
				NormalDelay("10s", "5s", "20s")
			})
		})
		Endpoint("/snafu/", func() {
			Method("GET", func() {
				Header("Content-Type", "application/xml")
				Header("Cache-Control", "no-cache")
				Header("Access-Control-Allow-Origin", "*")
				Switch(ExtractQueryParameter("foo"), func() {
					Case(StringEquals("bar"), func() {
						RespondWithFile(http.StatusOK, "response.xml")
					})
					Default(func() {
						RespondWithFile(http.StatusBadRequest, "error.xml")
					})
				})
			})
			NormalDelay("300ms", "120ms", "5s")
		})
	})

	log.Fatal(http.ListenAndServe(":8080", mockery))
}

Contributing

see Contributing

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package httpmock defines a DSL that can be used to create a set of mock endpoints.
Package httpmock defines a DSL that can be used to create a set of mock endpoints.
wiremock
Package wiremock provides a mechanism for importing wiremock Json API Mappings into mockery/httpmock.
Package wiremock provides a mechanism for importing wiremock Json API Mappings into mockery/httpmock.

Jump to

Keyboard shortcuts

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