test

package
v0.0.0-...-84d4e1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2019 License: MIT-0 Imports: 10 Imported by: 0

Documentation

Overview

test contains convenience types and functions used in BDD features

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoSequence

func DoSequence(step func(it int) error, count int) error

DoSequence performs the given step function, count times, in a sequence.

func DoThen

func DoThen(err error, next func() error) error

doThen is similar to expectThen except that it works with actions that either return an error or nil. This is useful when chaining steps

func Expect

func Expect(msg string) error

expect is a convenience function that denotes this is the last expectation from the chain

func ExpectThen

func ExpectThen(msg string, next func() error) error

expectThen is a convenience function that helps to chain an expectation after another. If the given msg is not empty then that means an expectation failed, and we translate it into an error. Otherwise we proceed with next.

Types

type Client

type Client struct {
	ServerUrl string

	Resp *httpclient.Response
	Json map[string]interface{}
	Text string
	Err  error
	// contains filtered or unexported fields
}

Client is a convenience api so that we can run queries against an existing server and read responses from it. This is currently used in BDD scenarios

func NewClient

func NewClient(serverUrl string) *Client

NewClient returns a new HTTP client for the given server

func (*Client) Delete

func (c *Client) Delete(path string)

Get performs a DELETE request on the given path and updates its last response record

func (*Client) Get

func (c *Client) Get(path string)

Get performs a GET request on the given path and updates its last response record

func (*Client) HasJson

func (c *Client) HasJson() bool

HasJson is a convenience function that returns true if the client has a json content-type in its last response

func (*Client) HasText

func (c *Client) HasText() bool

HasText is a convenience function that returns true if the client has a text/plain content-type in its last response

func (*Client) Post

func (c *Client) Post(path string, data string)

Post performs a POST request on the given path, with the given payload as json

func (*Client) Put

func (c *Client) Put(path string, data string)

Post performs a PUT request on the given path, with the given payload as json

func (*Client) UrlFor

func (c *Client) UrlFor(path string) string

UrlFor builds a url for the given path using the client's internal server configuration.

type PaymentData

type PaymentData struct {
	Id           string
	Version      int
	Organisation string
	Amount       string
}

PaymentData is a simplified representation of a payment, to be used in BDDs. Most of fields will be set by default, but here we declare the ones that are really significant in our tests

func (*PaymentData) ToJSON

func (p *PaymentData) ToJSON() string

ToJSON returns a json string from the payment data Most values that are not critical for our tests will be set to arbitrary defaults

type ScenarioData

type ScenarioData struct {
	// Holds a simplified representation of a Payment
	PaymentData *PaymentData

	// Generic datastructure where steps might store data
	// and read from it
	Subject interface{}
}

a ScenarioData struct is data for a particular scenario Each scenario needs to have a clean struct, in order to avoid side effects

type World

type World struct {
	Client *Client
	Data   *ScenarioData
	// contains filtered or unexported fields
}

a World is a simple context or container for features

func NewWorld

func NewWorld(serverUrl string, apiVersion string) *World

Return a new World container for the given server url and api version.

func (*World) APaymentWithId

func (w *World) APaymentWithId(id string) error

APaymentWithId defines a new payment in the current scenario context with the given id, and default values for the organisation and amount

func (*World) APaymentWithIdAmount

func (w *World) APaymentWithIdAmount(id string, amount string) error

APaymentWithIdAmount defines a new payment in the current scenario context with the given id and amount

func (*World) APaymentWithIdNoOrganisation

func (w *World) APaymentWithIdNoOrganisation(id string) error

APaymentWithIdNoOrganisation defines a new payment in the current scenario context with the given id, but no organisation set

func (*World) ICreatePayments

func (w *World) ICreatePayments(count int) error

ICreatePayments repeats many times the process of creating a new payment and verifying it was created, in a sequence

func (*World) ICreateThatPayment

func (w *World) ICreateThatPayment() error

ICreateThatPayment actually creates the payment defined in the world request data (as a string) by posting it to the payments endpoint, as json

func (*World) ICreatedANewPaymentWithId

func (w *World) ICreatedANewPaymentWithId(id string) error

ICreatedANewPaymentWithId combines logic from previous steps in order to provide a convenience Given step for payment fixtures in more complex scenarios

func (*World) ICreatedPayments

func (w *World) ICreatedPayments(count int) error

ICreatedPayments runs the ICreatePayments step and then verifies the repo info

func (*World) IDeleteAllData

func (w *World) IDeleteAllData() error

IDeleteAllData use the admin endpoints in order to delete all data

func (*World) IDeleteThatPayment

func (w *World) IDeleteThatPayment() error

IDeleteThatPayment sends a DELETE request for the payment defined in the scenario data. The delete operation requires a version information

func (*World) IDeleteThatPaymentWithoutSayingWhichVersion

func (w *World) IDeleteThatPaymentWithoutSayingWhichVersion() error

IDeleteThatPaymentWithoutSayingWhichVersion sends a DELETE request for the current payment, but does not specify a version

func (*World) IDeleteVersionOfThatPayment

func (w *World) IDeleteVersionOfThatPayment(v int) error

IDeleteVersionOfThatPayment deletes a specific version of payment

func (*World) IDeletedThatPayment

func (w *World) IDeletedThatPayment() error

IDeletedThatPayment combines logic from previous steps in order to provide a convenience Given step for payment fixtures in more complex scenarios

func (*World) IGetAllPayments

func (w *World) IGetAllPayments() error

IGetAllPayments performs a GET on the payments endpoint and stores the response details in the World context. This function fetches payments 0 to 19

func (*World) IGetPaymentsFromTo

func (w *World) IGetPaymentsFromTo(from int, to int) error

iGetPaymentsFromTo returns a subset of payments

func (*World) IGetPaymentsWithoutFromTo

func (w *World) IGetPaymentsWithoutFromTo() error

IGetPaymentsWithoutFromTo performs a GET on the payments endpoint and stores the response details in the World context. This function does not specify from/to query params

func (*World) IGetThatPayment

func (w *World) IGetThatPayment() error

IGetThatPayment sends a GET request for the payment defined in the scenario data.

func (*World) IGetTheRepoInfo

func (w *World) IGetTheRepoInfo() error

IGetTheRepoInfo uses the admin endpoints in order to get the current repository info

func (*World) IQueryTheHealthEndpoint

func (w *World) IQueryTheHealthEndpoint() error

IQueryTheHealthEndpoint performs a GET on the healthcheck endpoint and stores the response details in the World context

func (*World) IQueryTheMetricsEndpoint

func (w *World) IQueryTheMetricsEndpoint() error

iQueryTheMetricsEndpoint performs a GET on the metrics endpoint and stores the response details in the World context

func (*World) IShouldHaveAJson

func (w *World) IShouldHaveAJson() error

IShouldHaveAJson inspects the client's latest response and checks for a json document

func (*World) IShouldHaveAText

func (w *World) IShouldHaveAText() error

IShouldHaveAText inspects the client's latest response and checks for a string

func (*World) IShouldHaveContentType

func (w *World) IShouldHaveContentType(expected string) error

IShouldHaveContentType expects the client to have the given content type in its last response

func (*World) IShouldHavePayments

func (w *World) IShouldHavePayments(expected int) error

IShouldHavePayments fetches a list of payments and ensure the number of items returned is the expected

func (*World) IShouldHaveStatusCode

func (w *World) IShouldHaveStatusCode(expected int) error

IShouldHaveStatusCode expects the client to have the given status code in its last response

func (*World) IUpdateThatPayment

func (w *World) IUpdateThatPayment() error

IUpdateThatPayment sends a PUT request for the payment defined in the scenario data.

func (*World) IUpdateVersionOfThatPayment

func (w *World) IUpdateVersionOfThatPayment(v int) error

IUpdateVersionOfThatPayment updates a specific version of payment

func (*World) IUpdatedThatPayment

func (w *World) IUpdatedThatPayment() error

IUpdatedThatPayment combines logic from previous steps in order to provide a convenience Given step for payment fixtures in more complex scenarios

func (*World) NewData

func (w *World) NewData()

NewData creates a new, blank scenario data structure

func (*World) ThatJsonShouldHaveA

func (w *World) ThatJsonShouldHaveA(path string) error

ThatJsonShouldHaveA inspects the json, if any, in the current scenario data, and verifies the given json path exists

func (*World) ThatJsonShouldHaveInt

func (w *World) ThatJsonShouldHaveInt(path string, expected int) error

ThatJsonShouldHaveString inspects the json, if any, in the client and looks for the given field, and verifies it is equal to the given expected int value

func (*World) ThatJsonShouldHaveItems

func (w *World) ThatJsonShouldHaveItems(expected int) error

ThatJsonShouldHaveItems inspects the json, if any, and checks whether the data field contains an array with the expected number of items

func (*World) ThatJsonShouldHaveString

func (w *World) ThatJsonShouldHaveString(path string, expected string) error

ThatJsonShouldHaveString inspects the json, if any, in the client and looks for the given field, and verifies it is equal to the given expected string value

func (*World) ThatPaymentHasVersion

func (w *World) ThatPaymentHasVersion(v int) error

ThatPaymentHasVersion updates the version of the payment data in the current scenario data

func (*World) ThatTextShouldMatch

func (w *World) ThatTextShouldMatch(expected string) error

ThatTextShouldMatch inspects the json, if any, in the client and looks for the given field.

func (*World) TheRepoShouldHaveItems

func (w *World) TheRepoShouldHaveItems(expected int) error

TheRepoShouldHaveItems uses the admin repo info endpoint and verifies it returns the total number of items expected

func (*World) TheServiceIsUp

func (w *World) TheServiceIsUp() error

TheServiceIsUp checks the health check is reponding propertly

func (*World) ThereAreNoPayments

func (w *World) ThereAreNoPayments() error

ThereAreNoPayments ensure there is no data. This requires the target system to be started with admin routes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL