cli

package
v1.20.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TxExecutor

type TxExecutor struct {
	// Name is the name of the test. It's not actually used in here, but included
	// in case you want to use []TxExecutor to define your test cases.
	Name string
	// Cmd is the cobra.Command to execute.
	Cmd *cobra.Command
	// Args are all the arguments to provide to the command.
	Args []string

	// ExpErr, if true, the command must return an error.
	// If ExpErr is false, and both ExpErrMsg and ExpInErrMsg are empty, the command must NOT return an error.
	ExpErr bool
	// ExpErrMsg, if not empty, the command must return an error that equals this provided string.
	// If ExpErr is false, and both ExpErrMsg and ExpInErrMsg are empty, the command must NOT return an error.
	ExpErrMsg string
	// ExpInErrMsg, if not empty, the command must return an error that contains each of the provided strings.
	// If ExpErr is false, and both ExpErrMsg and ExpInErrMsg are empty, the command must NOT return an error.
	ExpInErrMsg []string

	// ExpCode is the expected response code from the Tx.
	ExpCode uint32

	// ExpRawLog, if not empty, the TxResponse.RawLog must equal this string.
	// If both ExpRawLog and ExpInRawLog are empty, the TxResponse.RawLog is ignored.
	ExpRawLog string
	// ExpInRawLog, if not empty, the TxResponse.RawLog must contain each of the provided strings.
	// If both ExpRawLog and ExpInRawLog are empty, the TxResponse.RawLog is ignored.
	ExpInRawLog []string
}

TxExecutor helps facilitate the execution and testing of a CLI command.

The command will be executed when either .Execute() or .AssertExecute() are called. The former will halt the test upon failure, the latter will allow test execution to continue.

The error returned from the command is tested against ExpErr, ExpErrMsg, and/or ExpInErrMsg. If none of those are set, the error form the command must be nil.

If the command did not return an error, the Tx is queried, so that we can check the actual result. That means that this will block for at least one block while it waits for the tx to be processed.

The result code and raw log are only checked if a Tx result is available. It's considered a failure if the command did not return an error, but the Tx result is not available.

func NewTxExecutor

func NewTxExecutor(cmd *cobra.Command, args []string) TxExecutor

NewTxExecutor creates a new TxExecutor with the provided command and args.

func (TxExecutor) AssertExecute

func (c TxExecutor) AssertExecute(t *testing.T, n *network.Network) (*sdk.TxResponse, bool)

AssertExecute executes the command, asserting that everything is as expected.

The returned TxResponse is nil if the command did not generate one, which is not dependent on the returned bool. The returned bool is true if everything is as expected, false otherwise.

To halt test execution on failure, use Execute.

func (TxExecutor) Execute

func (c TxExecutor) Execute(t *testing.T, n *network.Network) *sdk.TxResponse

Execute executes the command, requiring everything is as expected.

It is possible for everything to be as expected, and still get a nil TxResponse from this.

To allow test execution to continue on a failure, use AssertExecute.

func (TxExecutor) WithArgs

func (c TxExecutor) WithArgs(args []string) TxExecutor

WithArgs returns a copy of this TxExecutor that has the provided Args.

func (TxExecutor) WithCmd

func (c TxExecutor) WithCmd(cmd *cobra.Command) TxExecutor

WithCmd returns a copy of this TxExecutor that has the provided Cmd.

func (TxExecutor) WithExpCode

func (c TxExecutor) WithExpCode(expCode uint32) TxExecutor

WithExpCode returns a copy of this TxExecutor that has the provided ExpCode.

func (TxExecutor) WithExpErr

func (c TxExecutor) WithExpErr(expErr bool) TxExecutor

WithExpErr returns a copy of this TxExecutor that has the provided ExpErr.

func (TxExecutor) WithExpErrMsg

func (c TxExecutor) WithExpErrMsg(expErrMsg string) TxExecutor

WithExpErrMsg returns a copy of this TxExecutor that has the provided ExpErrMsg.

func (TxExecutor) WithExpInErrMsg

func (c TxExecutor) WithExpInErrMsg(expInErrMsg []string) TxExecutor

WithExpInErrMsg returns a copy of this TxExecutor that has the provided ExpInErrMsg.

func (TxExecutor) WithExpInRawLog

func (c TxExecutor) WithExpInRawLog(expInRawLog []string) TxExecutor

WithExpInRawLog returns a copy of this TxExecutor that has the provided ExpInRawLog.

func (TxExecutor) WithExpRawLog

func (c TxExecutor) WithExpRawLog(expRawLog string) TxExecutor

WithExpRawLog returns a copy of this TxExecutor that has the provided ExpRawLog.

func (TxExecutor) WithName

func (c TxExecutor) WithName(name string) TxExecutor

WithName returns a copy of this TxExecutor that has the provided Name.

Jump to

Keyboard shortcuts

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