Goodman is a Dredd hook handler implementation in Go. The API may change, please Vendor this library.
This package contains a Go Dredd hook handler which provides a bridge between the Dredd API Testing Framework and Go environment to ease implementation of testing hooks provided by Dredd. Write Dredd hooks in Go to glue together API Blueprint with your Go project
Not sure what these Dredd Hooks are? Read the Dredd documentation on them
The following are a few examples of what hooks can be used for:
- loading db fixtures
- cleanup after test step or steps
- handling authentication and sessions
- passing data between transactions (saving state from responses to stash)
- modifying request generated from blueprint
- changing generated expectations
- setting custom expectations
- debugging via logging stuff
Must use Dredd v1.1.0 or greater
go get github.com/snikch/goodman/cmd/goodman
1). Create a hook file in hooks.go
package main
import (
"fmt"
"github.com/snikch/goodman/hooks"
trans "github.com/snikch/goodman/transaction"
)
func main() {
h := hooks.NewHooks()
server := hooks.NewServer(hooks.NewHooksRunner(h))
h.Before("/message > GET", func(t *trans.Transaction) {
fmt.Println("before modification")
})
server.Serve()
defer server.Listener.Close()
})
2). Compile your hooks program
go build -o hooks path/to/hooks.go
3). Run it with dredd
dredd apiary.apib localhost:3000 --language go --hookfiles ./hooks
The hooks.Server
struct provides the following methods to hook into the following dredd transactions: before
, after
, before_all
, after_all
, before_each
, after_each
, before_validation
, and before_each_validation
.
The before
, before_validation
and after
hooks are identified by transaction name.
- Fork it
- Create your feature branch (git checkout -b my-newfeature)
- Commit your changes (git commit -am 'Add some feature')
- Push (git push origin my-new-feature)
- Create a new Pull Request
The test suite consists of go test suite and aruba/cucumber tests
Running the tests
-
go tests
go test github.com/snikch/{,/hooks,/transaction}
-
aruba tests
- Install local dredd copy
npm install
- Install aruba ruby gem
bundle install
- Run test suite
bundle exec cucumber
- Install local dredd copy