Documentation
¶
Overview ¶
Package integration contains some helpers for writing integration tests using BDD and Cucumber via godog (https://github.com/DATA-DOG/godog).
At a high level, to use this package you need to create a folder under this folder named `component` where component is the component you want to test with integration testing. Then add the following in `component/main_test.go`:
package component
import (
"os"
"testing"
"time"
"github.com/DATA-DOG/godog"
)
func TestMain(m *testing.M) {
status := godog.RunWithOptions("godog", func(s *godog.Suite) {
FeatureContext(s)
}, godog.Options{
Format: "progress",
Paths: []string{"features"},
Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order
})
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
And then run `$ mkdir component/features`. Create `component_test.go` with the following in it:
package component
type component struct {
*integration.Suite
}
func FeatureContext(s *godog.Suite) {
c := &component{
Suite: &integration.Suite{},
}
c.Register(s)
}
Then create features in component/features/*.feature, eg:
# user-creates-task.feature
Feature: A user can Create a Task
Background:
Given a base stack
Scenario:
As a User
When I try to create an example Task
Then there was no error
Then tear everything down
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Suite ¶
type Suite struct {
DB *sqlx.DB // raw SQL database in case you need it
// DAOs
Checks database.Checks
Runs database.Runs
RunInfos database.RunInfos
// Meta crap
Mux *http.ServeMux
TS *httptest.Server
ClientChecks lokahi.Checks
Err error
}
Suite is a group of story fragments. This includes some fun helpers for the life of this test suite as well as some setup and teardown code.
func (*Suite) GetErr ¶
GetErr fetches the suite active error.
The suggested story fragement for this function is:
Then there was no error
and should be followed up with an additional condition or two examining the error string for known values. It can be used with a FeatureContext function of something like:
func FeatureContext(s *godog.Suite) {
val := &feature{
Suite: &integration.Suite{},
}
s.Step(`^there was no error$`, val.Suite.GetErr)
}
This doesn't have any branches because the zero value for any go value boxed in an interface is nil.
func (*Suite) Register ¶
Register is a quick shortcut for registering all of the convenience shortcuts defined in the Suite type.
func (*Suite) Setup ¶
Setup reads configuration information from the environment and then uses this to set up an integration stack of lokahi.
The suggested story fragment for this function is:
Given a base stack
and it can be used with a function of something like:
func FeatureContext(s *godog.Suite) {
val := &feature{
Suite: &integration.Suite{},
}
s.Step(`^a base stack$`, val.Suite.Setup)
}
func (*Suite) Teardown ¶
Teardown destroys all resources that Setup allocated.
The suggested story fragment for this function is:
Then tear everything down
and it can be used with a function of something like:
func FeatureContext(s *godog.Suite) {
val := &feature{
Suite: &integration.Suite{},
}
s.Step(`^tear everything down$`, val.Suite.Teardown)
}
func (*Suite) WantAnError ¶
WantAnError asserts that the suite active error is non-nil. If the suite active error is nil for some reason, an error is returned.
The suggested story fragment for this function is:
Then there was an error
and should be followed up with an additional condition or two examining the error string for known values. It can be used with a FeatureContext function of something like:
func FeatureContext(s *godog.Suite) {
val := &feature{
Suite: &integration.Suite{},
}
s.Step(`^there was an error$`, val.Suite.WantAnError)
}