cmdrs

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: 3 Imported by: 0

Documentation

Overview

Package cmdrs has various built-in implementations of Commander for use in tests and examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteString

func WriteString(w io.Writer, s string) (err error)

WriteString writes to the Writer, discarding the returned byte count. The error is always non-nil if the returned count != len(s), so the count isn't interesting if all you care about is error existence. Handy in test assertions, e.g. assert.NoError(t, WriteString(w, "data"))

Types

type HoardingCommander

type HoardingCommander struct {
	KondoCommander
	// contains filtered or unexported fields
}

HoardingCommander keeps everything sent into Write. Handy for tests, debugging etc.

func NewHoardingCommander

func NewHoardingCommander(c string) *HoardingCommander

NewHoardingCommander returns a new instance of HoardingCommander.

func (*HoardingCommander) Reset

func (c *HoardingCommander) Reset()

Reset clears the internal buffer.

func (*HoardingCommander) Result

func (c *HoardingCommander) Result() string

Result returns the buffer contents as a string.

func (*HoardingCommander) Write

func (c *HoardingCommander) Write(b []byte) (int, error)

Write accepts input to store in a buffer.

type KondoCommander

type KondoCommander struct {
	Command string
}

KondoCommander quietly discards everything sent to Write and always reports Success true. Use this when you just want to run a command and don't care about the command's output.

func (*KondoCommander) Reset

func (c *KondoCommander) Reset()

Reset does nothing.

func (*KondoCommander) String

func (c *KondoCommander) String() string

String returns the command string.

func (*KondoCommander) Success

func (c *KondoCommander) Success() bool

Success always returns true.

func (*KondoCommander) Write

func (c *KondoCommander) Write(s []byte) (int, error)

Write accepts input to discard. Great place to debugging output.

type PrintingCommander

type PrintingCommander struct {
	KondoCommander
	// contains filtered or unexported fields
}

PrintingCommander echos everything to stdout. Only useful for examples, tests, debugging, etc.

func NewPrintingCommander

func NewPrintingCommander(c string, o io.Writer) *PrintingCommander

NewPrintingCommander returns a new instance of PrintingCommander.

func (*PrintingCommander) Write

func (c *PrintingCommander) Write(b []byte) (int, error)

Write accepts input to print.

type SimpleSentinelCommander

type SimpleSentinelCommander struct {
	Command string // the command, e.g. "echo Rumplestilskin"
	Value   string // the sentinel value to look for, e.g. "Rumplestilskin".
	// contains filtered or unexported fields
}

SimpleSentinelCommander is a Commander that asserts Success if it sees Value anywhere in the output of Command.

func (*SimpleSentinelCommander) Match

func (c *SimpleSentinelCommander) Match() string

Match returns the winning line.

func (*SimpleSentinelCommander) Reset

func (c *SimpleSentinelCommander) Reset()

Reset resets everything.

func (*SimpleSentinelCommander) String

func (c *SimpleSentinelCommander) String() string

func (*SimpleSentinelCommander) Success

func (c *SimpleSentinelCommander) Success() bool

Success returns true if Value found.

func (*SimpleSentinelCommander) Write

func (c *SimpleSentinelCommander) Write(b []byte) (int, error)

Write looks for Value anywhere in the line (so it had better be unambiguous).

Jump to

Keyboard shortcuts

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