mock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggingCache

type LoggingCache struct {
	Cache                map[string]*options.CachedLogger
	AllowCreateOverwrite bool
	FailCreate           bool
	AllowPutOverwrite    bool
	FailPut              bool
}

LoggingCache implements the LoggingCache interfaces based on an in-memory logging cache with exported fields to configure and introspect the mock's behavior.

func (*LoggingCache) Clear

func (c *LoggingCache) Clear(_ context.Context) error

Clear closes and removes all objects in the in-memory logging cache.

func (*LoggingCache) CloseAndRemove

func (c *LoggingCache) CloseAndRemove(_ context.Context, id string) error

CloseAndRemove closes the cached logger and removes it from the in-memory logging cache.

func (*LoggingCache) Create

func (c *LoggingCache) Create(id string, opts *options.Output) (*options.CachedLogger, error)

Create creates a cached logger from the given options.Output and stores it in the cache. If AllowCreateOverwrite is set, the newly created logger will overwrite an existing one with the same ID if it already exists. If FailCreate is set, it returns an error.

func (*LoggingCache) Get

Get returns an object from the in-memory logging cache.

func (*LoggingCache) Len

func (c *LoggingCache) Len() int

Len returns the size of the in-memory logging cache.

func (*LoggingCache) Prune

func (c *LoggingCache) Prune(lastAccessed time.Time)

Prune removes all items from the cache whose most recent access time is older than lastAccessed.

func (*LoggingCache) Put

func (c *LoggingCache) Put(id string, logger *options.CachedLogger) error

Put adds the given cached logger with the given ID to the cache. If AllowPutOverwrite is set, the given logger will overwrite an existing one with the same ID if it already exists. If FailPut is set, it returns an error.

func (*LoggingCache) Remove

func (c *LoggingCache) Remove(id string)

Remove removes an object from the in-memory logging cache.

type Manager

type Manager struct {
	FailCreate      bool
	FailRegister    bool
	FailList        bool
	FailGroup       bool
	FailGet         bool
	FailClose       bool
	NilLoggingCache bool
	FailWriteFile   bool
	Create          func(*options.Create) Process
	CreateConfig    Process
	ManagerID       string
	Procs           []jasper.Process
	ScriptingEnv    scripting.Harness
	LoggingCacheVal jasper.LoggingCache

	// WriteFile input
	WriteFileOptions options.WriteFile
}

Manager implements the Manager interface with exported fields to configure and introspect the mock's behavior.

func (*Manager) Clear

func (m *Manager) Clear(ctx context.Context)

Clear removes all processes from Procs.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

Close clears all processes in Procs. If FailClose is set, it returns an error.

func (*Manager) CreateCommand

func (m *Manager) CreateCommand(ctx context.Context) *jasper.Command

CreateCommand creates a Command that invokes CreateProcess to create the underlying processes.

func (*Manager) CreateProcess

func (m *Manager) CreateProcess(ctx context.Context, opts *options.Create) (jasper.Process, error)

CreateProcess creates a new mock Process. If Create is set, it is invoked to create the mock Process. Otherwise, CreateConfig is used as a template to create the mock Process. The new mock Process is put in Procs. If FailCreate is set, it returns an error.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (jasper.Process, error)

Get returns a process given by ID from Procs. If a matching process is not found in Procs or if FailGet is set, it returns an error.

func (*Manager) Group

func (m *Manager) Group(ctx context.Context, tag string) ([]jasper.Process, error)

Group returns all processses that have the given tag. If FailGroup is set, it returns an error.

func (*Manager) ID

func (m *Manager) ID() string

ID returns the ManagerID field.

func (*Manager) List

func (m *Manager) List(ctx context.Context, f options.Filter) ([]jasper.Process, error)

List returns all processes that match the given filter. If FailList is set, it returns an error.

func (*Manager) LoggingCache

func (m *Manager) LoggingCache(ctx context.Context) jasper.LoggingCache

LoggingCache returns the implementation's logging cache.

func (*Manager) Register

func (m *Manager) Register(ctx context.Context, proc jasper.Process) error

Register adds the process to Procs. If FailRegister is set, it returns an error.

func (*Manager) WriteFile

func (m *Manager) WriteFile(ctx context.Context, opts options.WriteFile) error

type Process

type Process struct {
	FailRespawn                 bool
	FailRegisterTrigger         bool
	FailRegisterSignalTrigger   bool
	FailRegisterSignalTriggerID bool
	FailSignal                  bool
	FailWait                    bool
	WaitExitCode                int

	ProcInfo         jasper.ProcessInfo
	Triggers         jasper.ProcessTriggerSequence `json:"-"`
	SignalTriggers   jasper.SignalTriggerSequence  `json:"-"`
	SignalTriggerIDs []jasper.SignalTriggerID
	Signals          []syscall.Signal
	Tags             []string
}

Process implements the Process interface with exported fields to configure and introspect the mock's behavior.

func (*Process) Complete

func (p *Process) Complete(ctx context.Context) bool

Complete returns the Complete field set by the user.

func (*Process) GetTags

func (p *Process) GetTags() []string

GetTags returns all tags set by the user or using Tag.

func (*Process) ID

func (p *Process) ID() string

ID returns the ID set in ProcInfo set by the user.

func (*Process) Info

func (p *Process) Info(ctx context.Context) jasper.ProcessInfo

Info returns the ProcInfo set by the user.

func (*Process) RegisterSignalTrigger

func (p *Process) RegisterSignalTrigger(ctx context.Context, t jasper.SignalTrigger) error

RegisterSignalTrigger records the signal trigger in SignalTriggers. If FailRegisterSignalTrigger is set, it returns an error.

func (*Process) RegisterSignalTriggerID

func (p *Process) RegisterSignalTriggerID(ctx context.Context, sigID jasper.SignalTriggerID) error

RegisterSignalTriggerID records the ID of the signal trigger in SignalTriggers. If FailRegisterSignalTriggerID is set, it returns an error.

func (*Process) RegisterTrigger

func (p *Process) RegisterTrigger(ctx context.Context, t jasper.ProcessTrigger) error

RegisterTrigger records the trigger in Triggers. If FailRegisterTrigger is set, it returns an error.

func (*Process) ResetTags

func (p *Process) ResetTags()

ResetTags removes all tags stored in Tags.

func (*Process) Respawn

func (p *Process) Respawn(ctx context.Context) (jasper.Process, error)

Respawn creates a new Process, which has a copy of all the fields in the current Process. If FailRespawn is set, it returns an error.

func (*Process) Running

func (p *Process) Running(ctx context.Context) bool

Running returns the IsRunning field set by the user.

func (*Process) Signal

func (p *Process) Signal(ctx context.Context, sig syscall.Signal) error

Signal records the signals sent to the process in Signals. If FailSignal is set, it returns an error.

func (*Process) Tag

func (p *Process) Tag(tag string)

Tag adds to the Tags slice.

func (*Process) Wait

func (p *Process) Wait(ctx context.Context) (int, error)

Wait returns the ExitCode set by the user in ProcInfo. If FailWait is set, it returns exit code -1 and an error.

Jump to

Keyboard shortcuts

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