Categorygithub.com/armakuni/dp-go-featuretest
modulepackage
0.0.0-20210225121618-47aebd5e92b6
Repository: https://github.com/armakuni/dp-go-featuretest.git
Documentation: pkg.go.dev

# README

dp-go-featuretest

Library to help write feature-level tests against a REST api / microservice

Background

The intention of this library is to help when writing feature tests for a new or existing REST API. The library contains a set of useful helper feature steps to make writing new gherkin tests easy.

The steps in api_feature have been written as to be easily reusable when setting up tests against a REST API, and there are other additional parts of this library which can be plugged in to help test outputs of the tests e.g. setting up an in memory mongo to assert against changes to the database.

Installation

To install this package in your project simply run:

go get github.com/armakuni/dp-go-featuretest

This package works alongside the Godog BDD framework, to install this run:

go get github.com/cucumber/godog/cmd/[email protected]

NOTE: this library will eventually change ownership

Running tests

To set up and run tests using Godog, it is best to follow the instructions found here

To run Godog tests with the API testing features in this library all you need to do is update your root level test file to pass the http handler of your application to our NewAPIFeature, register the steps and add the reset function to the BeforeScenario function.

package main

import (
	featuretest "github.com/armakuni/dp-go-featuretest"
	"github.com/cucumber/godog"
)

func InitializeScenario(ctx *godog.ScenarioContext) {
	myAppFeature := NewMyAppFeature() // This is the part that YOU will implement
	apiFeature := featuretest.NewAPIFeature(myAppFeature.Handler)

	ctx.BeforeScenario(func(*godog.Scenario) {
		apiFeature.Reset()
	})
	ctx.AfterScenario(func(*godog.Scenario, error) {
	})

	apiFeature.RegisterSteps(ctx)
}

func InitializeTestSuite(ctx *godog.TestSuiteContext) {
	ctx.BeforeSuite(func() {
	})
}

Repository structure

The features that can be used all exist on the root level of the project.

The examples folder contains three different examples of how to use this library, each using different features and having a slightly different way of setting up.

# Packages

No description provided by the author

# Functions

NewAPIFeature returns a new APIFeature, takes a function to retrieve the bound handler just before a request is made.
NewAPIFeatureWithHandler create a new APIFeature with a handler already bound with your endpoints.
No description provided by the author
NewMongoFeature creates a new in-memory mongo database using the supplied options.
No description provided by the author

# Structs

APIFeature contains the information needed to test REST API requests.
No description provided by the author
No description provided by the author
MongoFeature is a struct containing an in-memory mongo database.
MongoOptions contains a set of options required to create a new MongoFeature.

# Type aliases

No description provided by the author