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 ¶
- func Context() context.Context
- func Database(t *testing.T) *sqlx.DB
- func DatabaseURL() string
- func LoadScenario(scenarioName string)
- func LoadScenarioWithoutHorizon(scenarioName string)
- func OverrideLogger(l *log.Entry)
- func PaydexCoreDatabase(t *testing.T) *sqlx.DB
- func PaydexCoreDatabaseURL() string
- func RequestHelperRaw(r *http.Request)
- func RequestHelperRemoteAddr(ip string) func(r *http.Request)
- func RequestHelperStreaming(r *http.Request)
- func RequestHelperXFF(xff string) func(r *http.Request)
- func ResetHorizonDB(t *testing.T, db *sqlx.DB)
- func RestoreLogger()
- func ShouldBeErr(a interface{}, options ...interface{}) string
- type RequestHelper
- type StaticMockServer
- type T
- func (t *T) CoreSession() *db.Session
- func (t *T) Finish()
- func (t *T) HorizonSession() *db.Session
- func (t *T) Scenario(name string) *T
- func (t *T) ScenarioWithoutHorizon(name string) *T
- func (t *T) UnmarshalExtras(r io.Reader) map[string]string
- func (t *T) UnmarshalNext(r io.Reader) string
- func (t *T) UnmarshalPage(r io.Reader, dest interface{}) hal.Links
- func (t *T) UpdateLedgerState()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func 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 ¶
Database returns a connection to the horizon test database
DEPRECATED: use `Horizon()` from test/db package
func DatabaseURL ¶
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 ¶
func LoadScenarioWithoutHorizon(scenarioName string)
LoadScenarioWithoutHorizon populates the test Paydex core database a with pre-created scenario. Unlike `LoadScenario`, this
func OverrideLogger ¶
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 PaydexCoreDatabase ¶
PaydexCoreDatabase returns a connection to the paydex core test database
DEPRECATED: use `PaydexCore()` from test/db package
func PaydexCoreDatabaseURL ¶
func PaydexCoreDatabaseURL() string
PaydexCoreDatabaseURL returns the database connection the url any test use when connecting to the paydex-core database
DEPRECATED: use `PaydexCoreURL()` from test/db package
func RequestHelperRaw ¶
func RequestHelperRemoteAddr ¶
func RequestHelperStreaming ¶
func RequestHelperXFF ¶
func ResetHorizonDB ¶
ResetHorizonDB sets up a new horizon database with empty tables
func RestoreLogger ¶
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
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 *chi.Mux) RequestHelper
type StaticMockServer ¶
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 HorizonDB *sqlx.DB CoreDB *sqlx.DB Logger *log.Entry LogMetrics *logmetrics.Metrics LogBuffer *bytes.Buffer }
T provides a common set of functionality for each test in horizon
func (*T) CoreSession ¶
CoreSession returns a db.Session instance pointing at the paydex core test database
func (*T) Finish ¶
func (t *T) Finish()
Finish finishes the test, logging any accumulated horizon logs to the logs output
func (*T) HorizonSession ¶
HorizonSession returns a db.Session instance pointing at the horizon test database
func (*T) ScenarioWithoutHorizon ¶
ScenarioWithoutHorizon loads the named sql scenario into the database
func (*T) UnmarshalExtras ¶
UnmarshalExtras extracts and returns extras content
func (*T) UnmarshalNext ¶
UnmarshalNext extracts and returns the next link
func (*T) UnmarshalPage ¶
UnmarshalPage populates dest with the records contained in the json-encoded page in r
func (*T) UpdateLedgerState ¶
func (t *T) UpdateLedgerState()
UpdateLedgerState updates the cached ledger state (or panicing on failure).