Mock HTTP Service that can register mock endpoints and respond with respective responses.
- Registering mock endpoints by request by sending a
POST
request to an URL path of your choice - Registering the mock registration endpoint and bulk loading pre-determined requests of your choice
- Registering endpoints that can send callbacks hooks back to your service
- Registering endpoints that return specific responses based on timing; used to mock APIs that require polling to keep on top of statuses
- Client SDKs to create mock endpoints and the responses in the mock service for testing purposes
- YAML support for simplified configuration files
- Dockerfile and sample docker-compose file that can be used with services under test
mockService, err := mockservice.New("/mocks")
if err != nil {
log.Fatalf("Failed to created mock service %s", err)
}
http.ListenAndServe(":8080", mockService)
To register HTTP responses, send POST
requests to /mocks
with a JSON request body like the following
{
"method": "GET",
"endpoint": " ",
"httpStatusCode": 204,
"responseBody": "",
"responseHeaders": { "foo": "bar" }
}
Note: JSON and XML configuration files can also be loaded by unmarshaling into mockservice.Conf
. See here and here for details.
conf := mockservice.Conf{
RegistrationEndpoint: "/mocks",
Endpoints: []*mockservice.MockEndpoint{
{
Method: http.MethodPost,
Endpoint: "/mock/test",
StatusCode: http.StatusCreated,
ResponseBody: `hello world`,
ResponseHeaders: map[string]string{"Foo": "Bar"},
},
},
}
service, err := mockservice.NewWithConf(&conf)
In order to contribute, please:
- Check if an issue that you'd like to contribute a fix for doesn't already exist
- Create an issue for something you'd like fixed
- Fork the repository
- Make a pull request
Please also be sure to follow the following guidelines.
go fmt
all your codegolint
all your code