Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meowgorithm/baby-blackbox
Blackbox testing for Go JSON APIs (and babies)
https://github.com/meowgorithm/baby-blackbox
blackbox-testing go goji testing
Last synced: 5 days ago
JSON representation
Blackbox testing for Go JSON APIs (and babies)
- Host: GitHub
- URL: https://github.com/meowgorithm/baby-blackbox
- Owner: meowgorithm
- License: mit
- Created: 2018-06-11T18:03:28.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-16T22:49:47.000Z (over 4 years ago)
- Last Synced: 2024-10-31T11:41:33.954Z (about 2 months ago)
- Topics: blackbox-testing, go, goji, testing
- Language: Go
- Homepage: https://godoc.org/github.com/meowgorithm/baby-blackbox
- Size: 17.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![GoDoc Badge](https://godoc.org/github.com/meowgorithm/baby-blackbox?status.svg)](http://godoc.org/github.com/meowgorithm/baby-blackbox)
Baby Blackbox
=============Blackbox testing for Go JSON APIs. Currently, it supports the Go standard
library’s Multiplexer (`http.ServeMux`) and the [Goji][goji] multiplexer
(`goji.Mux`). If there's another multiplexer you'd like it to support let us
know.[goji]: http://goji.io
## Example
```go
package main_test
import (
"testing"
blackbox "github.com/meowgorithm/baby-blackbox"
app "."
)type user struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
}type apiError {
Code int `json:"code"`
Message string `json:"message"`
}func TestMain(m *testing.M) {
os.Exit(m.Run())
}func TestStuff(t *testing.T) {
// Create a blackbox testing thing from your application's multiplexer
api := blackbox.New(t, app.GetMux())// The payload we'll send in the next request
u := user{Name: "Frankie"}// Create a user expecting to get an ID back in a JSON object. We assert
// that we want a 201 Created status code.
api.Request("POST", "/user", u).
Created().
JSON(&u)// Make sure we got an ID in the response
if u.ID == 0 {
t.Error("expected to receive an ID, but we did not")
}var apiErr apiError
// Check another route, expecting a 401 Unauthorized error
api.Request("GET", "/cats", nil).
Status(http.StatusUnauthorized).
JSON(&apiErr)if err.Code != 21 {
t.Errorf("thought we were gonna get error code 21, instead got %d", err.Code)
}
}```
For an example in the context of a more complete application, see the `example`
directory.## License
MIT