test

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package test contains simple test helpers that should not have any dependencies on aurora's packages. think constants, custom matchers, generic helpers etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context() context.Context

Context provides a context suitable for testing in tests that do not create a full App instance (in which case your tests should be using the app's context). This context has a logger bound to it suitable for testing.

func Database

func Database(t *testing.T) *sqlx.DB

Database returns a connection to the aurora test database

DEPRECATED: use `Aurora()` from test/db package

func DatabaseURL

func DatabaseURL() string

DatabaseURL returns the database connection the url any test use when connecting to the history/aurora database

DEPRECATED: use `AuroraURL()` from test/db package

func DiamcircleCoreDatabase

func DiamcircleCoreDatabase(t *testing.T) *sqlx.DB

DiamcircleCoreDatabase returns a connection to the diamcircle core test database

DEPRECATED: use `DiamcircleCore()` from test/db package

func DiamcircleCoreDatabaseURL

func DiamcircleCoreDatabaseURL() string

DiamcircleCoreDatabaseURL returns the database connection the url any test use when connecting to the diamcircle-core database

DEPRECATED: use `DiamcircleCoreURL()` from test/db package

func RequestHelperRaw

func RequestHelperRaw(r *http.Request)

func RequestHelperStreaming

func RequestHelperStreaming(r *http.Request)

func ResetAuroraDB

func ResetAuroraDB(t *testing.T, db *sqlx.DB)

ResetAuroraDB sets up a new aurora database with empty tables

Types

type Assertions

type Assertions struct {
	*assert.Assertions
}

Assertions provides an assertions helper. Custom assertions for this package can be defined as methods on this struct. foo

func (*Assertions) PageOf

func (a *Assertions) PageOf(length int, body *bytes.Buffer) bool

func (*Assertions) Problem

func (a *Assertions) Problem(body *bytes.Buffer, expected problem.P) bool

Problem asserts that `body` is a serialized problem equal to `expected`, using Type and Status to compare for equality.

func (*Assertions) ProblemType

func (a *Assertions) ProblemType(body *bytes.Buffer, typ string) bool

ProblemType asserts that the provided `body` is a JSON serialized problem whose type is `typ`

type RequestHelper

type RequestHelper interface {
	Get(string, ...func(*http.Request)) *httptest.ResponseRecorder
	Post(string, url.Values, ...func(*http.Request)) *httptest.ResponseRecorder
}

func NewRequestHelper

func NewRequestHelper(router *chi.Mux) RequestHelper

type StaticMockServer

type StaticMockServer struct {
	*httptest.Server
	LastRequest *http.Request
}

StaticMockServer is a test helper that records it's last request

func NewStaticMockServer

func NewStaticMockServer(response string) *StaticMockServer

NewStaticMockServer creates a new mock server that always responds with `response`

type T

type T struct {
	T          *testing.T
	Assert     *assert.Assertions
	Require    *require.Assertions
	Ctx        context.Context
	AuroraDB   *sqlx.DB
	CoreDB     *sqlx.DB
	EndLogTest func() []logrus.Entry
}

T provides a common set of functionality for each test in aurora

func Start

func Start(t *testing.T) *T

Start initializes a new test helper object, a new instance of log, and conceptually "starts" a new test

func (*T) AuroraSession

func (t *T) AuroraSession() *db.Session

AuroraSession returns a db.Session instance pointing at the aurora test database

func (*T) CoreSession

func (t *T) CoreSession() *db.Session

CoreSession returns a db.Session instance pointing at the diamcircle core test database

func (*T) Finish

func (t *T) Finish()

Finish finishes the test, logging any accumulated aurora logs to the logs output

func (*T) LoadLedgerStatus

func (t *T) LoadLedgerStatus() ledger.Status

LoadLedgerStatus loads ledger state from the core db(or panicing on failure).

func (*T) Scenario

func (t *T) Scenario(name string) ledger.Status

Scenario loads the named sql scenario into the database

func (*T) ScenarioWithoutAurora

func (t *T) ScenarioWithoutAurora(name string) ledger.Status

ScenarioWithoutAurora loads the named sql scenario into the database

func (*T) UnmarshalExtras

func (t *T) UnmarshalExtras(r io.Reader) map[string]string

UnmarshalExtras extracts and returns extras content

func (*T) UnmarshalNext

func (t *T) UnmarshalNext(r io.Reader) string

UnmarshalNext extracts and returns the next link

func (*T) UnmarshalPage

func (t *T) UnmarshalPage(r io.Reader, dest interface{}) hal.Links

UnmarshalPage populates dest with the records contained in the json-encoded page in r

Directories

Path Synopsis
Package db provides helpers to connect to test databases.
Package db provides helpers to connect to test databases.
Package transactions offers common infrastructure for testing Transactions
Package transactions offers common infrastructure for testing Transactions

Jump to

Keyboard shortcuts

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