tstcli

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TestCliPath expected to be on the PATH when tests run.
	TestCliPath       = "testcli"
	FlagDisablePrompt = "disable-prompt"
	FlagExitOnErr     = "exit-on-error"
	FlagFailOnStartup = "fail-on-startup"
	FlagNumRowsInDb   = "num-rows-in-db"
	FlagRowToErrorOn  = "row-to-error-on"
)

Program name and flags needed for tests.

View Source
const (
	CmdHelp = "help"
	CmdQuit = "quit"
	CmdEcho = "echo"

	CmdSleep = "sleep"

	CmdQuery = "query"
)

All individual commands.

Variables

View Source
var AllCommands = []string{
	CmdHelp,
	CmdSleep,
	cmdVersion,
	CmdQuit,
	CmdEcho,
	cmdStatus,
	cmdSet,
	cmdPrint,
	CmdQuery,
}

AllCommands can be used in help and validation.

Functions

func MakeErrSentinelCommander

func MakeErrSentinelCommander() *cmdrs.SimpleSentinelCommander

MakeErrSentinelCommander returns a sentinel commander with a command that's unknown to the testcli; it triggers an error when used.

func MakeOutSentinelCommander

func MakeOutSentinelCommander() *cmdrs.SimpleSentinelCommander

MakeOutSentinelCommander returns a sentinel commander that has testcli echo something unique to the output.

func MakeSleepCommander

func MakeSleepCommander(d time.Duration) *cmdrs.HoardingCommander

MakeSleepCommander Returns a command that makes the testcli sleep for the given duration. Used in testing timeouts.

Types

type Shell

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

Shell parses stdin, executing anything that validates as a command. See AllCommands for a complete list of recognized commands. This code exists to drive tests of the cli package.

func NewShell

func NewShell(db *SillyDb, disablePrompt, exitOnError bool, help string) *Shell

NewShell returns a new instance.

func (*Shell) Run

func (s *Shell) Run() error

Run starts a loop to drain the shells input stream, executing commands.

type SillyDb

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

SillyDb responds to a query by printing generated data. The data is sequential hex32 numbers (primary ids) paired with some fake data.

func NewSillyDb

func NewSillyDb(numRowsInDb, rowToErrorOn int) *SillyDb

NewSillyDb returns a new instance.

func (*SillyDb) DoLookupQuery

func (db *SillyDb) DoLookupQuery(id string) error

DoLookupQuery prints some lines to stdout, representing a query result.

func (*SillyDb) DoScanQuery

func (db *SillyDb) DoScanQuery(offset, limit int) error

DoScanQuery prints n lines to stdout, representing a query result.

func (*SillyDb) NumRowsInDb

func (db *SillyDb) NumRowsInDb() int

NumRowsInDb returns the row count.

func (*SillyDb) RowToErrorOn

func (db *SillyDb) RowToErrorOn() int

RowToErrorOn reports the row which ill cause an error if it is accessed.

Jump to

Keyboard shortcuts

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