query

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTestCase

func RunTestCase[R any, S any](s TestSuiter, td TestDef[R, S], tc TestCase[R, S])

RunTestCase runs a unit test on a QueryServer endpoint. A cached context is used so each test case won't affect the others. R is the request message type. S is the response message type.

Types

type TestCase

type TestCase[R any, S any] struct {
	// Name is the name of the test case.
	Name string
	// Setup is a function that does any needed app/state setup.
	// A cached context is used for tests, so this setup will not carry over between test cases.
	Setup func()
	// Req is the request message to provide to the query.
	Req *R
	// ExpectedResp is the expected response from the query
	ExpectedResp *S
	// ExpectedErrSubstrs is the strings that are expected to be in the error returned by the endpoint.
	// If empty, that error is expected to be nil.
	ExpectedErrSubstrs []string
}

TestCase is a test case for a QueryServer endpoint. R is the request message type. S is the response message type.

type TestDef

type TestDef[R any, S any] struct {
	// QueryName is the name of the query being tested.
	QueryName string
	// Query is the query function to invoke.
	Query func(goCtx context.Context, req *R) (*S, error)
	// ManualEquality is a function that allows the tester to define their own equality tests.
	ManualEquality func(s TestSuiter, expected, actual *S)
}

TestDef is the definition of a QueryServer endpoint to be tested. R is the request message type. S is the response message type.

type TestSuiter

type TestSuiter interface {
	Context() sdk.Context
	SetContext(ctx sdk.Context)
	Require() *require.Assertions
	Assert() *assert.Assertions
}

Jump to

Keyboard shortcuts

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