Expressive end-to-end HTTP API testing made easy in Go
Expressive and versatile end-to-end HTTP API testing made easy in Go (golang), built on top of gentleman HTTP client toolkit.
Take a look to the examples to get started.
testing package (more test engines might be added in the future).gentleman@v2. Recommended.gentleman@v2.gentleman@v1. Actively maintained.go get -u gopkg.in/h2non/baloo.v3See examples directory for featured examples.
package simple
import (
"testing"
"gopkg.in/h2non/baloo.v3"
)
// test stores the HTTP testing client preconfigured
var test = baloo.New("http://httpbin.org")
func TestBalooSimple(t *testing.T) {
test.Get("/get").
SetHeader("Foo", "Bar").
Expect(t).
Status(200).
Header("Server", "apache").
Type("json").
JSON(map[string]string{"bar": "foo"}).
Done()
}…package json_schema
import (
"testing"
"gopkg.in/h2non/baloo.v3"
)
const schema = `{
"title": "Example Schema",
"type": "object",
"properties": {
"origin": {
"type": "string"
}
},
"required": ["origin"]
}`
// test stores the HTTP testing client preconfigured
var test = baloo.New("http://httpbin.org")
func TestJSONSchema(t *testing.T) {
test.Get("/ip").
Expect(t).
Status(200).
Type("json").
JSONSchema(schema).
Done()
}…See godoc reference for detailed API documentation.
Asserts the response HTTP status code to be equal.
Asserts the response HTTP status to be within the given numeric range.
Asserts the response HTTP status to be a valid server response (>= 200 && = 400 && = 500 && = 400 && < 500).
Asserts the Content-Type header. MIME type aliases can be used as kind argument.
Supported aliases: json, xml, html, form, text and urlencoded.
Asserts a response header field value matches.
Regular expressions can be used as value to perform the specific assertions.
Asserts a response header field with the given value.
Asserts that a response header field is not equal to the given value.
Asserts if a header field is present in the response.
Asserts if a header field is not present in the response.
Asserts a response body as string using strict comparison.
Regular expressions can be used as value to perform the specific assertions.
Asserts a response body matching a string expression.
Regular expressions can be used as value to perform the specific assertions.
Asserts the response body length.
Asserts the response body with the given JSON struct.
Asserts the response body againts the given JSON schema definition.
data argument can be a string containing the JSON schema, a file path
or an URL pointing to the JSON schema definition.
Assert adds a new assertion function by alias name.
Assertion function must be previosly registered via baloo.AddAssertFunc("alias", function).
See an example here.
Adds a new custom assertion function who should return an detailed error in case that the assertion fails.
Clone this repository:
git clone https://github.com/h2non/baloo.git && cd balooInstall dependencies:
go get -u ./...Run tests:
go test ./...Lint code:
go test ./...Run example:
go test ./_examples/simple/simple_test.goMIT - Tomas Aparicio
No open issues yet, or sync has not completed.