go-test

module
v0.0.0-...-1553c39 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: Apache-2.0

README

go-test

This is go library project for test cases.

mock server

You can easily make a mock response for a http request by using this.


//Define httpClient you want to add a patch.
httpClient := http.DefaultClient
//Define a target server with domain and add ResponseHandlers. ResponseHandler contains a mock response and a request should be handled.
testServer := mock.NewTargetServer("google.com").AddResponseHandler(&mock.ResponseHandler{
	WriteToBody: func() []byte {
		return []byte(testBody)
	},
	Path:       "/",
	Method:     http.MethodGet,
	StatusCode: 400,
})
//After PatchClient, every http request using the httpClient will handle the mock request.
clientPatcher := mock.PatchClient(httpClient, testServer)
//RemovePatch will remove all mock handlers from the httpClient.
defer clientPatcher.RemovePatch()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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