README

Goodman Godoc Reference Travis Status

Goodman is a Dredd hook handler implementation in Go. The API may change, please Vendor this library.

About

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

Installing

Must use Dredd v1.1.0 or greater

go get github.com/snikch/goodman/cmd/goodman

Usage

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

API

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.

How to Contribute

  1. Fork it
  2. Create your feature branch (git checkout -b my-newfeature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push (git push origin my-new-feature)
  5. Create a new Pull Request

Tests

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
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyRunner

type DummyRunner struct{}

func (*DummyRunner) Close

func (r *DummyRunner) Close()

func (*DummyRunner) RunAfter

func (r *DummyRunner) RunAfter(t *transaction.Transaction)

func (*DummyRunner) RunAfterAll

func (r *DummyRunner) RunAfterAll(t *[]*transaction.Transaction)

func (*DummyRunner) RunAfterEach

func (r *DummyRunner) RunAfterEach(t *transaction.Transaction)

func (*DummyRunner) RunBefore

func (r *DummyRunner) RunBefore(t *transaction.Transaction)

func (*DummyRunner) RunBeforeAll

func (r *DummyRunner) RunBeforeAll(t *[]*transaction.Transaction)

func (*DummyRunner) RunBeforeEach

func (r *DummyRunner) RunBeforeEach(t *transaction.Transaction)

func (*DummyRunner) RunBeforeEachValidation

func (r *DummyRunner) RunBeforeEachValidation(t *transaction.Transaction)

func (*DummyRunner) RunBeforeValidation

func (r *DummyRunner) RunBeforeValidation(t *transaction.Transaction)

type Run

type Run struct {
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(rpcService string, port int) (*Run, error)

func (*Run) Close

func (r *Run) Close()

func (*Run) RunAfter

func (r *Run) RunAfter(t *transaction.Transaction)

func (*Run) RunAfterAll

func (r *Run) RunAfterAll(t *[]*transaction.Transaction)

func (*Run) RunAfterEach

func (r *Run) RunAfterEach(t *transaction.Transaction)

func (*Run) RunBefore

func (r *Run) RunBefore(t *transaction.Transaction)

func (*Run) RunBeforeAll

func (r *Run) RunBeforeAll(t *[]*transaction.Transaction)

func (*Run) RunBeforeEach

func (r *Run) RunBeforeEach(t *transaction.Transaction)

func (*Run) RunBeforeEachValidation

func (r *Run) RunBeforeEachValidation(t *transaction.Transaction)

func (*Run) RunBeforeValidation

func (r *Run) RunBeforeValidation(t *transaction.Transaction)

type Runner

type Runner interface {
	RunBeforeAll(t *[]*transaction.Transaction)
	RunBeforeEach(t *transaction.Transaction)
	RunBefore(t *transaction.Transaction)
	RunBeforeEachValidation(t *transaction.Transaction)
	RunBeforeValidation(t *transaction.Transaction)
	RunAfterAll(t *[]*transaction.Transaction)
	RunAfterEach(t *transaction.Transaction)
	RunAfter(t *transaction.Transaction)
	Close()
}

type Server

type Server struct {
	Runner           []Runner
	Port             string
	MessageDelimeter []byte
	// contains filtered or unexported fields
}

    Server is responsible for starting a server and running lifecycle callbacks.

    func NewServer

    func NewServer(runners []Runner) *Server

      NewServer returns a new server instance with the supplied runner. If no runner is supplied, a new one will be created.

      func (*Server) ProcessMessage

      func (server *Server) ProcessMessage(m *message) error

        ProcessMessage handles a single event message.

        func (*Server) Run

        func (server *Server) Run() error

          Run starts the server listening for events from dredd.

          func (*Server) RunAfter

          func (server *Server) RunAfter(trans *t.Transaction)

          func (*Server) RunAfterAll

          func (server *Server) RunAfterAll(trans *[]*t.Transaction)

          func (*Server) RunAfterEach

          func (server *Server) RunAfterEach(trans *t.Transaction)

          func (*Server) RunBefore

          func (server *Server) RunBefore(trans *t.Transaction)

          func (*Server) RunBeforeAll

          func (server *Server) RunBeforeAll(trans *[]*t.Transaction)

          func (*Server) RunBeforeEach

          func (server *Server) RunBeforeEach(trans *t.Transaction)

          func (*Server) RunBeforeEachValidation

          func (server *Server) RunBeforeEachValidation(trans *t.Transaction)

          func (*Server) RunBeforeValidation

          func (server *Server) RunBeforeValidation(trans *t.Transaction)

          Directories

          Path Synopsis
          cmd