test

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: Apache-2.0, BSD-2-Clause-Views, BSD-3-Clause, + 1 more Imports: 21 Imported by: 0

Documentation

Overview

Package test contains simple test helpers that should not have any dependencies on horizon'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 ContextWithLogBuffer

func ContextWithLogBuffer() (context.Context, *bytes.Buffer)

ContextWithLogBuffer returns a context and a buffer into which the new, bound logger will write into. This method allows you to inspect what data was logged more easily in your tests.

func Database added in v0.5.0

func Database() *sqlx.DB

Database returns a connection to the horizon test database

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

func DatabaseURL added in v0.5.0

func DatabaseURL() string

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

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

func LoadScenario

func LoadScenario(scenarioName string)

LoadScenario populates the test databases with pre-created scenarios. Each scenario is in the scenarios subfolder of this package and are a pair of sql files, one per database.

func LoadScenarioWithoutHorizon added in v0.5.0

func LoadScenarioWithoutHorizon(scenarioName string)

LoadScenarioWithoutHorizon populates the test Stellar core database a with pre-created scenario. Unlike `LoadScenario`, this

func OverrideLogger added in v0.6.0

func OverrideLogger(l *hlog.Entry)

OverrideLogger sets the default logger used by horizon to `l`. This is used by the testing system so that we can collect output from logs during test runs. Panics if the logger is already overridden.

func RequestHelperRaw added in v0.6.0

func RequestHelperRaw(r *http.Request)

func RequestHelperRemoteAddr

func RequestHelperRemoteAddr(ip string) func(r *http.Request)

func RequestHelperStreaming

func RequestHelperStreaming(r *http.Request)

func RequestHelperXFF

func RequestHelperXFF(xff string) func(r *http.Request)

func RestoreLogger added in v0.6.0

func RestoreLogger()

RestoreLogger restores the default horizon logger after it is overridden using a call to `OverrideLogger`. Panics if the default logger is not presently overridden.

func ShouldBeErr

func ShouldBeErr(a interface{}, options ...interface{}) string

func StellarCoreDatabase added in v0.5.0

func StellarCoreDatabase() *sqlx.DB

StellarCoreDatabase returns a connection to the stellar core test database

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

func StellarCoreDatabaseURL added in v0.5.0

func StellarCoreDatabaseURL() string

StellarCoreDatabaseURL returns the database connection the url any test use when connecting to the stellar-core database

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

Types

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 *web.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 added in v0.5.0

type T struct {
	T          *testing.T
	Assert     *assert.Assertions
	Require    *require.Assertions
	Ctx        context.Context
	HorizonDB  *sqlx.DB
	CoreDB     *sqlx.DB
	Logger     *hlog.Entry
	LogMetrics *hlog.Metrics
	LogBuffer  *bytes.Buffer
}

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

func Start added in v0.5.0

func Start(t *testing.T) *T

Start initializes a new test helper object and conceptually "starts" a new test

func (*T) CoreSession added in v0.10.1

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

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

func (*T) Finish added in v0.5.0

func (t *T) Finish()

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

func (*T) HorizonSession added in v0.10.1

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

HorizonSession returns a db.Session instance pointing at the horizon test database

func (*T) Scenario added in v0.5.0

func (t *T) Scenario(name string) *T

Scenario loads the named sql scenario into the database

func (*T) ScenarioWithoutHorizon added in v0.5.0

func (t *T) ScenarioWithoutHorizon(name string) *T

ScenarioWithoutHorizon loads the named sql scenario into the database

func (*T) UnmarshalPage added in v0.7.1

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

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

func (*T) UpdateLedgerState added in v0.6.0

func (t *T) UpdateLedgerState()

UpdateLedgerState updates the cached ledger state (or panicing on failure).

Directories

Path Synopsis
Package db provides helpers to connect to test databases.
Package db provides helpers to connect to test databases.

Jump to

Keyboard shortcuts

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