Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadEnv ¶
func LoadEnv()
Loads the environment for the tests. It must be called before `m.Run` in the TestMain function of each package. It looks for a `.env.<testEnv>` file in the `internal/tests` directory, where `<testEnv>` is the value of the `-env` flag. If the file is not found, a warning is logged.
func PrettyPrint ¶ added in v0.16.0
func PrettyPrint(data interface{})
PrettyPrint pretty marshals the data with indentation and prints it.
func RunTestOn ¶
Runs the test only if the environment is in the list of environments provided. If no environment is provided, the test fails. If the environment is not in the list of environments, the test is skipped.
Packages like `account` and `rpc` are run on multiple environments, so in order to easily skip tests that are not supported on a specific environment, we use this helper. If a test is not supported on a specific environment, it should be skipped; otherwise, it could pass (since the environment is not being tested) and give a false positive.
Types ¶
type Spy ¶ added in v0.16.0
type Spy struct {
// contains filtered or unexported fields
}
The purpose of the Spy type is to spy on the JSON-RPC calls made by the client. It's used in the tests to mock the JSON-RPC calls and to check if the client is making the correct calls.
func (*Spy) CallContext ¶ added in v0.16.0
func (s *Spy) CallContext( ctx context.Context, result interface{}, method string, arg interface{}, ) error
CallContext calls the spy function with the given context, result, method, and arguments.
Parameters:
- ctx: the context.Context to be used.
- result: the interface{} to store the result of the function call.
- method: the string representing the method to be called.
- arg: argument to be passed to the function call.
Returns:
- error: an error if any occurred during the function call
func (*Spy) CallContextWithSliceArgs ¶ added in v0.16.0
func (s *Spy) CallContextWithSliceArgs( ctx context.Context, result interface{}, method string, args ...interface{}, ) error
CallContextWithSliceArgs calls the spy CallContext function with args as a slice.
Parameters:
- ctx: the context.Context to be used.
- result: the interface{} to store the result of the function call.
- method: the string representing the method to be called.
- args: variadic arguments to be passed to the function call.
Returns:
- error: an error if any occurred during the function call
func (*Spy) LastResponse ¶ added in v0.16.0
func (s *Spy) LastResponse() json.RawMessage
LastResponse returns the last response captured by the spy. In other words, it returns the raw JSON response received from the server when calling a `callCloser` method.
type Spyer ¶ added in v0.16.0
type Spyer interface {
CallContext(ctx context.Context, result interface{}, method string, args interface{}) error
CallContextWithSliceArgs(
ctx context.Context,
result interface{},
method string,
args ...interface{},
) error
Close()
LastResponse() json.RawMessage
}
The Spyer interface implemented by the Spy type.
func NewJSONRPCSpy ¶ added in v0.16.0
NewJSONRPCSpy creates a new spy object.
It takes a client callCloser as the first parameter and an optional debug parameter. The client callCloser is the interface that the spy will be based on. The debug parameter is a variadic parameter that specifies whether debug mode is enabled.
Parameters:
- client: the interface that the spy will be based on
- debug: a boolean flag indicating whether to print debug information
Returns:
- spy: a new spy object