double

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFake

func NewFake(opts ...FakeOption) cli.Command

NewFake creates a new fake implementation of the cli.Command interface.

By default, the fake command only implements the basic Execute method, returning nil. Use the FakeWith* options to implement additional interfaces and customize behavior.

Types

type FakeOption

type FakeOption func(f *fakeAllInterfaces)

FakeOption is a function to configures a fake behavior.

func FakeWithContext

func FakeWithContext(f func(context.Context) context.Context) FakeOption

FakeWithContext configures the fake to implement the Context method. The provided function will be called when the Context method is invoked.

func FakeWithDescription

func FakeWithDescription(f func() string) FakeOption

FakeWithDescription configures the fake to implement the Description method. The provided function will be called when the Description method is invoked.

func FakeWithExamples

func FakeWithExamples(f func() []string) FakeOption

FakeWithExamples configures the fake to implement the Examples method. The provided function will be called when the Examples method is invoked.

func FakeWithExecute

func FakeWithExecute(f func(context.Context, []string, []string) error) FakeOption

FakeWithExecute configures the fake to implement the Execute method. The provided function will be called when the Execute method is invoked.

func FakeWithFlags

func FakeWithFlags(f func() []cli.Flag) FakeOption

FakeWithFlags configures the fake to implement the Flags method. The provided function will be called when the Flags method is invoked.

func FakeWithHook

func FakeWithHook(f func() *cli.Hook) FakeOption

FakeWithHook configures the fake to implement the Hook method. The provided function will be called when the Hook method is invoked.

func FakeWithPersistentFlags

func FakeWithPersistentFlags(f func() []cli.Flag) FakeOption

FakeWithPersistentFlags configures the fake to implement the PersistentFlags method. The provided function will be called when the PersistentFlags method is invoked.

func FakeWithPersistentHook

func FakeWithPersistentHook(f func() *cli.PersistentHook) FakeOption

FakeWithPersistentHook configures the fake to implement the PersistentHook method. The provided function will be called when the PersistentHook method is invoked.

func FakeWithUsage

func FakeWithUsage(f func() string) FakeOption

FakeWithUsage configures the fake to implement the Usage method. The provided function will be called when the Usage method is invoked.

type Spy

type Spy struct {
	// contains filtered or unexported fields
}

Spy records and provides access to method call records on CLI commands. It maintains thread-safe access to records of all method calls made on commands in the wrapped CLI tree.

func SpyCLI

func SpyCLI(c *cli.CLI) (*Spy, *cli.CLI)

SpyCLI creates a spy wrapper around a CLI instance to track method calls. It returns both the spy object for assertions and the wrapped CLI for use in tests. The spy records all method calls made on any command in the CLI tree, allowing verification of call sequences and parameters.

func (*Spy) AssertCommandMethodCalled

func (spy *Spy) AssertCommandMethodCalled(t test.TestingT, cmdPath []string, methodName string, once bool)

AssertCommandMethodCalled verifies that a specific method was called on a command. The cmdPath parameter specifies the path to the command in the CLI tree (e.g., ["root", "sub"]). The methodName parameter is the name of the method to check (e.g., "Execute", "Description"). If once is true, the method must have been called exactly once. If once is false, the method must have been called at least once. The test will fail if the assertion is not met.

func (*Spy) AssertCommandMethodSequence

func (spy *Spy) AssertCommandMethodSequence(t test.TestingT, cmdPath []string, expectedMethods ...string)

AssertCommandMethodSequence verifies that methods were called in the specified order for a command path. The command path is specified by the names of the commands in the tree, and methodNames contains the sequence of method calls that is expected.

This is useful for verifying the exact sequence of operations performed during command execution, such as ensuring hooks, flags, and execution happen in the correct order.

func (*Spy) AssertCommandRecords

func (spy *Spy) AssertCommandRecords(t test.TestingT, cmdPath []string, check func([]SpyCommandRecord) error)

AssertCommandRecords validates the recorded method calls for a specific command using a custom check function. It collects all SpyCommandRecord entries for the specified command path and passes them to the check function. The cmdPath parameter specifies the path to the command in the CLI tree (e.g., ["root", "sub"]). The check function receives all records for that command and should return an error if validation fails. This method is useful for complex assertions that require custom logic beyond simple method counting or sequencing.

func (*Spy) CountCommandMethodCalls

func (spy *Spy) CountCommandMethodCalls(cmdPath []string, methodName string) uint

CountCommandMethodCalls returns the number of times a specific method was called on a command. The cmdPath parameter specifies the path to the command in the CLI tree (e.g., ["root", "sub"]) and methodName is the name of the method to count (e.g., "Execute", "Description"). Returns 0 if the method was never called or the command path doesn't exist.

func (*Spy) DebugMethods

func (spy *Spy) DebugMethods(t test.TestingT)

DebugMethods logs all recorded method calls to the test output for debugging purposes. For each recorded method call, it prints the command path and method name in the format "[command.path] MethodName called". This is useful for understanding the sequence of method calls during test debugging.

func (*Spy) ForEachCommandRecords

func (spy *Spy) ForEachCommandRecords(cb func(tree []*cli.CLI, record SpyCommandRecord))

ForEachCommandRecords iterates through all recorded method calls in chronological order. For each record, it calls the provided callback with the command tree path and the record. This allows for custom processing or validation of the recorded method calls.

type SpyCommandRecord

type SpyCommandRecord struct {
	Method  string
	Inputs  []any
	Outputs []any
}

SpyCommandRecord represents a single method call on a spy-wrapped CLI command. It captures the method name, input parameters, and output values to enable verification of method calls during testing.

Directories

Path Synopsis
internal
generator command

Jump to

Keyboard shortcuts

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