Documentation ¶
Index ¶
- Constants
- func AdaptFuncsToCmdStub(stubFuncs []StubFunc, repeatLast bool) func(sreq StubRequest) *ExecOutcome
- func AdaptOutcomeToCmdStub(outcome *ExecOutcome) func(sreq StubRequest) *ExecOutcome
- func AdaptOutcomesToCmdStub(outcomes []*ExecOutcome, repeatLast bool) func(sreq StubRequest) *ExecOutcome
- func CfgDefaultTimeout() time.Duration
- func CmdConfigTmpl() (script []byte, err error)
- func EffectuateAlternativeExecOutcome(stubFunc StubFunc)
- func EffectuateConfiguredExecOutcome(extraJobOnStubRequestForStaticMode func(StubRequest) error)
- func EffectuateDynamicOutcome(timeout time.Duration, pipePathStubber string, pipePathTestHelperProc string, ...) (exitCode uint8)
- func ExecOutcomeEncoderFunc(writer io.Writer) func(outcome *ExecOutcome) error
- func StubRequestEncoderFunc(writer io.Writer) func(outcome *StubRequest) error
- func StubbingOngoing() bool
- func ValueDuration(o OptionalDuration) (valueX time.Duration, err error)
- func ValueUint8(o OptionalUint8) (value uint8, err error)
- func WriteStubRequestToNamedPipe(pipePath string, stubReq StubRequest, timeout time.Duration) error
- type CmdConfig
- func (cfg CmdConfig) CreateConfigFile(cmdDir string) error
- func (cfg CmdConfig) ExitCodeTxt() string
- func (cfg CmdConfig) ExitCodeUint8() (exitcode uint8, err error)
- func (cfg CmdConfig) StderrAvail() bool
- func (cfg CmdConfig) StdoutAvail() bool
- func (cfg CmdConfig) StubRequestWith(args []string) StubRequest
- func (cfg CmdConfig) TimeoutAsDuration() (timeout time.Duration, err error)
- func (cfg CmdConfig) TimeoutAsDurationOrDefault() (timeout time.Duration)
- func (cfg CmdConfig) TimeoutAsFormattedNanos() string
- func (cfg CmdConfig) UseDynamicOutcome() bool
- func (cfg CmdConfig) UseStaticOutCome() bool
- func (cfg CmdConfig) UseTestHelperProcess() bool
- type DiscoveredBy
- type DiscoveredByHomeDirBinData
- type ExecOutcome
- type ExecType
- type OptionalDuration
- type OptionalUint8
- type Settings
- func (s *Settings) DiscoveredByHomeDirBin(envHomeKey string, binDirs ...string)
- func (s *Settings) DiscoveredByPath()
- func (s *Settings) ExecTypeBash()
- func (s *Settings) ExecTypeExe()
- func (s Settings) InModDyna() bool
- func (s Settings) InModStatic() bool
- func (s Settings) IsCmdDiscoveredByHomeDir() bool
- func (s Settings) IsUsingExecTypeBash() bool
- func (s Settings) IsUsingTestProcessHelper() bool
- func (s *Settings) ModeDanymic()
- func (s *Settings) ModeStatic()
- func (s *Settings) WithTestProcessHelper(methodName string)
- func (s *Settings) WithoutTestProcessHelper()
- type StubFunc
- type StubRequest
- type StubRequestDirRepo
- type StubbingMode
Constants ¶
const ( // DiscoveredByPath specifies that the command is discovered using environment path DiscoveredByPath = "PATH" // DiscoveredByHomeBinDir specifies that the command is discovered using // an home directory setting in environment. DiscoveredByHomeBinDir = "HomeBinDir" )
const ( // ExecTypeExe requires the use of an Executable for the stubbing ExecTypeExe = "EXE" // ExecTypeBash requires the use of a bash script for the stubbing ExecTypeBash = "BASH" )
const ( // StubbingModeStatic requires static stubbing. // The stubfunc will be evaludated immediately (before the command execution) // with zero request. // The outcome is static and cannot depend on the command arguments StubbingModeStatic = "STATIC" // StubbingModeDyna reuqires dynamic stubbing. // The stub-func will be evaluated online (reacting to the command execution) // The outome ca there for depends on command arguments StubbingModeDyna = "DYNAMIC" )
Variables ¶
This section is empty.
Functions ¶
func AdaptFuncsToCmdStub ¶
func AdaptFuncsToCmdStub( stubFuncs []StubFunc, repeatLast bool, ) func(sreq StubRequest) *ExecOutcome
AdaptFuncsToCmdStub returns a CmdStub which will use a list of function to procudes the execution outcomes.
func AdaptOutcomeToCmdStub ¶
func AdaptOutcomeToCmdStub( outcome *ExecOutcome, ) func(sreq StubRequest) *ExecOutcome
AdaptOutcomeToCmdStub returns a StubFunc which will return the given outcome.
func AdaptOutcomesToCmdStub ¶
func AdaptOutcomesToCmdStub( outcomes []*ExecOutcome, repeatLast bool, ) func(sreq StubRequest) *ExecOutcome
AdaptOutcomesToCmdStub returns a CmdStub which will yield the given outcomes.
func CfgDefaultTimeout ¶
CfgDefaultTimeout return default value of timeout in not provided.
func CmdConfigTmpl ¶
CmdConfigTmpl returns the template used to generate stub cmd configuration.
func EffectuateAlternativeExecOutcome ¶
func EffectuateAlternativeExecOutcome(stubFunc StubFunc)
EffectuateAlternativeExecOutcome effectuates an alternative outcome to the configured one for test helper processes.
func EffectuateConfiguredExecOutcome ¶
func EffectuateConfiguredExecOutcome( extraJobOnStubRequestForStaticMode func(StubRequest) error, )
EffectuateConfiguredExecOutcome effectuates the configured static or dynamic outcome for test helper processes.
func EffectuateDynamicOutcome ¶
func EffectuateDynamicOutcome( timeout time.Duration, pipePathStubber string, pipePathTestHelperProc string, req StubRequest, stderr io.Writer, stdout io.Writer, ) (exitCode uint8)
EffectuateDynamicOutcome uses IPC to request execution outcome from running test.
func ExecOutcomeEncoderFunc ¶
func ExecOutcomeEncoderFunc(writer io.Writer) func(outcome *ExecOutcome) error
ExecOutcomeEncoderFunc return an encoder which can write exec outcome representation into the writer.
func StubRequestEncoderFunc ¶
func StubRequestEncoderFunc(writer io.Writer) func(outcome *StubRequest) error
StubRequestEncoderFunc return an encoder which can write stubbing request representation into the writer.
func StubbingOngoing ¶
func StubbingOngoing() bool
StubbingOngoing tells whether the current process is run as stub instead of an actual execution. The check is based of off process environment
func ValueDuration ¶
func ValueDuration(o OptionalDuration) (valueX time.Duration, err error)
ValueDuration returns the duration value if present or an error.
func ValueUint8 ¶
func ValueUint8(o OptionalUint8) (value uint8, err error)
ValueUint8 returns the uint8 value if present or an error.
func WriteStubRequestToNamedPipe ¶
func WriteStubRequestToNamedPipe( pipePath string, stubReq StubRequest, timeout time.Duration, ) error
WriteStubRequestToNamedPipe write the stubbing request to the named pipe
Types ¶
type CmdConfig ¶
type CmdConfig struct { StubKey string CmdToStub string UnitTestExec string TestHelperProcessMethod string TxtStdout string TxtStderr string ExitCode OptionalUint8 PipeStubber string PipeTestHelperProcess string Timeout OptionalDuration DataDir string }
CmdConfig holds configuration data for an executable used for stubbing
func CmdConfigForCommand ¶
CmdConfigForCommand loads the configuration for the given executable identified by its path.
func CmdConfigLoadedFromFile ¶
CmdConfigLoadedFromFile loads the configuration from the given file path.
func (CmdConfig) CreateConfigFile ¶
CreateConfigFile create a file holding the configuration state at the given directory.
func (CmdConfig) ExitCodeTxt ¶
ExitCodeTxt return the text representation of the exit code.
func (CmdConfig) ExitCodeUint8 ¶
ExitCodeUint8 returns the configured exit code.
func (CmdConfig) StderrAvail ¶
StderrAvail return true if stderr data are available; false otherwise.
func (CmdConfig) StdoutAvail ¶
StdoutAvail return true if stdout data are available; false otherwise.
func (CmdConfig) StubRequestWith ¶
func (cfg CmdConfig) StubRequestWith(args []string) StubRequest
StubRequestWith returns a stub request that requests execution of the configured cmd with the given arguments.
func (CmdConfig) TimeoutAsDuration ¶
TimeoutAsDuration returns configured timeout as time.Duration.
func (CmdConfig) TimeoutAsDurationOrDefault ¶
TimeoutAsDurationOrDefault returns configured timeout as time.Duration, or the default timeout in any misconfiguration.
func (CmdConfig) TimeoutAsFormattedNanos ¶
TimeoutAsFormattedNanos return a string nanos integer representation of the configured timeout.
func (CmdConfig) UseDynamicOutcome ¶
UseDynamicOutcome tells whether the use of dynamic outcome is configured.
func (CmdConfig) UseStaticOutCome ¶
UseStaticOutCome stells whether the us of static outcome is configured.
func (CmdConfig) UseTestHelperProcess ¶
UseTestHelperProcess tells whether the use of test helper process is configured.
type DiscoveredByHomeDirBinData ¶
type DiscoveredByHomeDirBinData struct { EnvHomeKey string // BinDirs bin sub directory paths. // using to avoid guessing path separator BinDirs []string }
DiscoveredByHomeDirBinData holds data used to the home environment key and the binary sub-directory structure which contains the executable e.g. For Java: EnvHomeKey=JAVA_HOME and BinDirs=[]string{"bin"}
so that the java binary is located in ${JAVA_HOME}/bin/
type ExecOutcome ¶
type ExecOutcome struct { Key string // Expected command exec outcome // the receiving side is expected forward them as is Stdout string Stderr string ExitCode uint8 InternalErrTxt string }
ExecOutcome modells what happens when the stubbed command is executed. It basically the content of std-out and std-err and the error code the stubbed command us supposed to yield. The stubber may encounter some internal err. In that case: - InternalErrTxt is provided. - ExitCode does not hold a meaningfull value - The requesting side should not use it as the expected exit code Not using an typed error here in order to ease serialization during ipc and allow usage both as dto and stubbing function return type.
func ExecOutcomeDecoderFunc ¶
func ExecOutcomeDecoderFunc(reader io.Reader) (*ExecOutcome, error)
ExecOutcomeDecoderFunc decodes an exec-outcome from the given reader.
func ReadStubbingResponseFromNamedPipe ¶
func ReadStubbingResponseFromNamedPipe(pipePath string, timeout time.Duration) (*ExecOutcome, error)
ReadStubbingResponseFromNamedPipe reads the stubbing outcome from the named pipe.
func (ExecOutcome) InternalErrTxtAvail ¶
func (o ExecOutcome) InternalErrTxtAvail() bool
InternalErrTxtAvail return true if InternalErrTxt is available (not "") and false otherwise.
func (ExecOutcome) StderrAvail ¶
func (o ExecOutcome) StderrAvail() bool
StderrAvail return true if Stderr is available (not "") and false otherwise.
func (ExecOutcome) StdoutAvail ¶
func (o ExecOutcome) StdoutAvail() bool
StdoutAvail return true if Stdout is available (not "") and false otherwise.
type OptionalDuration ¶
type OptionalDuration interface{}
OptionalDuration is an time.Duration or nil to fake optional type for time.Duration. It may legly holds the following type as long as the valze is within the rang of time.Duration: int,int8/16/32/64,uint,uint8/16/32/64
type OptionalUint8 ¶
type OptionalUint8 interface{}
OptionalUint8 is an uint8 or nil to fake optional type for unit8. It may legaly holds the following types as long as their value is within the rang of uint8: int,int8/16/32/64,uint,uint8/16/32/64
type Settings ¶
type Settings struct { DiscoveredBy DiscoveredBy DiscoveredByHomeDirBinData DiscoveredByHomeDirBinData ExecType ExecType Mode StubbingMode TestHelperProcessMethodName string Timeout OptionalDuration }
Settings holds setting data for an exec stubbing
func SettingsDynaStubCmdDiscoveredByPath ¶
func SettingsDynaStubCmdDiscoveredByPath() *Settings
SettingsDynaStubCmdDiscoveredByPath constructs a new Settings for dynamically stubbing a cmd which is discovered by Path.
func (*Settings) DiscoveredByHomeDirBin ¶
DiscoveredByHomeDirBin selects discovery by home dir
func (*Settings) DiscoveredByPath ¶
func (s *Settings) DiscoveredByPath()
DiscoveredByPath selects discovery by path
func (*Settings) ExecTypeBash ¶
func (s *Settings) ExecTypeBash()
ExecTypeBash sets exec type to BASH
func (Settings) InModStatic ¶
InModStatic returns true if in mode static false otherwise.
func (Settings) IsCmdDiscoveredByHomeDir ¶
IsCmdDiscoveredByHomeDir true is cmd are set to be discovered by home-dir.
func (Settings) IsUsingExecTypeBash ¶
IsUsingExecTypeBash returns true bash is specified as exec type; false otherwise.
func (Settings) IsUsingTestProcessHelper ¶
IsUsingTestProcessHelper returns true if TestProcessHelper is provided and expected to be used; false otherwise.
func (*Settings) ModeDanymic ¶
func (s *Settings) ModeDanymic()
ModeDanymic set stubbing mode to dynamic
func (*Settings) ModeStatic ¶
func (s *Settings) ModeStatic()
ModeStatic set stubbing mode to static
func (*Settings) WithTestProcessHelper ¶
WithTestProcessHelper requires the use a test process helper.
func (*Settings) WithoutTestProcessHelper ¶
func (s *Settings) WithoutTestProcessHelper()
WithoutTestProcessHelper requires stubbing without the use of a test process helper
type StubFunc ¶
type StubFunc func(sreq StubRequest) *ExecOutcome
StubFunc function use to produce the outcome for a stubbed command execution
func RecordingExecutions ¶
func RecordingExecutions( stubFunc StubFunc, ) (recordingStubFunc StubFunc, reqsStore *[]StubRequest)
RecordingExecutions adds request recording feature to the given StubFunc
type StubRequest ¶
type StubRequest struct { // Key identifies the stubbing setup Key string CmdName string Args []string }
StubRequest holds data send to a stubber through a ComChannel to request stubbing
func StopOperationRequest ¶
func StopOperationRequest() *StubRequest
func StubRequestDecoderFunc ¶
func StubRequestDecoderFunc(reader io.Reader) (*StubRequest, error)
StubRequestDecoderFunc decodes an stubbing request from the given reader.
func (StubRequest) IsRequestingStop ¶
func (req StubRequest) IsRequestingStop() bool
func (StubRequest) String ¶
func (req StubRequest) String() string
type StubRequestDirRepo ¶
type StubRequestDirRepo struct {
// contains filtered or unexported fields
}
StubRequestDirRepo a repository to save and load stubbing requests from a directory.
func NewStubRequestDirRepo ¶
func NewStubRequestDirRepo(dataDir string) StubRequestDirRepo
NewStubRequestDirRepo creates a new stubbing request repo given the data directory.
func (StubRequestDirRepo) DeleteAll ¶
func (repo StubRequestDirRepo) DeleteAll() error
DeleteAll deletes all persisted requests.
func (StubRequestDirRepo) FindAll ¶
func (repo StubRequestDirRepo) FindAll() (requests *[]StubRequest, err error)
FindAll return all persisted requests.
func (StubRequestDirRepo) Save ¶
func (repo StubRequestDirRepo) Save(req StubRequest) error
Save saves the given request.
type StubbingMode ¶
type StubbingMode string
StubbingMode specifies the stubing mode (static or dynamic).