mock

package
v4.0.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Values map[string]CacheItem
}

Cache provides a mock cache implementation

func (*Cache) Add

func (c *Cache) Add(ctx context.Context, key string, value []byte, ttl *time.Duration) error

Add a mock cache item

func (*Cache) Close

func (c *Cache) Close(ctx context.Context) error

Close does nothing

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, key string) error

Delete a mock cache item

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, error)

Get a mock cache item

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value []byte, ttl *time.Duration) error

Set a mock cache item

func (*Cache) SetMulti

func (c *Cache) SetMulti(ctx context.Context, kvs map[string]cache.TTLItem) error

SetMulti sets multiple mock cache items

type CacheItem

type CacheItem struct {
	Value string
	TTL   *time.Duration
}

CacheItem represents a cached key/ttl pair.

type Input

type Input struct {
	TChan chan message.Transaction
	// contains filtered or unexported fields
}

Input provides a mocked input implementation.

func NewInput

func NewInput(batches []*message.Batch) *Input

NewInput creates a new mock input that will return transactions containing a list of batches, then exit.

func (*Input) CloseAsync

func (f *Input) CloseAsync()

CloseAsync does nothing.

func (*Input) Connected

func (f *Input) Connected() bool

Connected always returns true.

func (*Input) TransactionChan

func (f *Input) TransactionChan() <-chan message.Transaction

TransactionChan returns a transaction channel.

func (*Input) WaitForClose

func (f *Input) WaitForClose(time.Duration) error

WaitForClose does nothing.

type Manager

type Manager struct {
	Inputs     map[string]*Input
	Caches     map[string]map[string]CacheItem
	RateLimits map[string]RateLimit
	Outputs    map[string]OutputWriter
	Processors map[string]Processor
	Pipes      map[string]<-chan message.Transaction

	// OnRegisterEndpoint can be set in order to intercept endpoints registered
	// by components.
	OnRegisterEndpoint func(path string, h http.HandlerFunc)
}

Manager provides a mock benthos manager that components can use to test interactions with fake resources.

func NewManager

func NewManager() *Manager

NewManager provides a new mock manager.

func (*Manager) AccessCache

func (m *Manager) AccessCache(ctx context.Context, name string, fn func(cache.V1)) error

AccessCache executes a closure on a cache resource.

func (*Manager) AccessInput

func (m *Manager) AccessInput(ctx context.Context, name string, fn func(input.Streamed)) error

AccessInput executes a closure on an input resource.

func (*Manager) AccessOutput

func (m *Manager) AccessOutput(ctx context.Context, name string, fn func(output.Sync)) error

AccessOutput executes a closure on an output resource.

func (*Manager) AccessProcessor

func (m *Manager) AccessProcessor(ctx context.Context, name string, fn func(processor.V1)) error

AccessProcessor executes a closure on a processor resource.

func (*Manager) AccessRateLimit

func (m *Manager) AccessRateLimit(ctx context.Context, name string, fn func(ratelimit.V1)) error

AccessRateLimit executes a closure on a rate limit resource.

func (*Manager) BloblEnvironment

func (m *Manager) BloblEnvironment() *bloblang.Environment

BloblEnvironment always returns the global environment.

func (*Manager) ForStream

func (m *Manager) ForStream(id string) interop.Manager

ForStream returns the same mock manager.

func (*Manager) GetPipe

func (m *Manager) GetPipe(name string) (<-chan message.Transaction, error)

GetPipe attempts to find a service wide transaction chan by its name.

func (*Manager) IntoPath

func (m *Manager) IntoPath(segments ...string) interop.Manager

IntoPath returns the same mock manager.

func (*Manager) Label

func (m *Manager) Label() string

Label always returns empty.

func (*Manager) Logger

func (m *Manager) Logger() log.Modular

Logger returns a no-op logger.

func (*Manager) Metrics

func (m *Manager) Metrics() metrics.Type

Metrics returns a no-op metrics.

func (*Manager) Path

func (m *Manager) Path() []string

Path always returns empty.

func (*Manager) ProbeCache

func (m *Manager) ProbeCache(name string) bool

ProbeCache returns true if a cache resource exists under the provided name.

func (*Manager) ProbeInput

func (m *Manager) ProbeInput(name string) bool

ProbeInput returns true if an input resource exists under the provided name.

func (*Manager) ProbeOutput

func (m *Manager) ProbeOutput(name string) bool

ProbeOutput returns true if an output resource exists under the provided name.

func (*Manager) ProbeProcessor

func (m *Manager) ProbeProcessor(name string) bool

ProbeProcessor returns true if a processor resource exists under the provided name.

func (*Manager) ProbeRateLimit

func (m *Manager) ProbeRateLimit(name string) bool

ProbeRateLimit returns true if a rate limit resource exists under the provided name.

func (*Manager) RegisterEndpoint

func (m *Manager) RegisterEndpoint(path, desc string, h http.HandlerFunc)

RegisterEndpoint registers a server wide HTTP endpoint.

func (*Manager) SetPipe

func (m *Manager) SetPipe(name string, t <-chan message.Transaction)

SetPipe registers a transaction chan under a name.

func (*Manager) UnsetPipe

func (m *Manager) UnsetPipe(name string, t <-chan message.Transaction)

UnsetPipe removes a named transaction chan.

func (*Manager) WithAddedMetrics

func (m *Manager) WithAddedMetrics(m2 metrics.Type) interop.Manager

WithAddedMetrics returns the same mock manager.

type OutputChanneled

type OutputChanneled struct {
	TChan <-chan message.Transaction
}

OutputChanneled implements the output.Type interface around an exported transaction channel.

func (*OutputChanneled) CloseAsync

func (m *OutputChanneled) CloseAsync()

CloseAsync does nothing.

func (*OutputChanneled) Connected

func (m *OutputChanneled) Connected() bool

Connected returns true.

func (*OutputChanneled) Consume

func (m *OutputChanneled) Consume(msgs <-chan message.Transaction) error

Consume sets the read channel. This implementation is NOT thread safe.

func (OutputChanneled) WaitForClose

func (m OutputChanneled) WaitForClose(t time.Duration) error

WaitForClose does nothing.

type OutputWriter

type OutputWriter func(context.Context, message.Transaction) error

OutputWriter provides a mock implementation of types.OutputWriter.

func (OutputWriter) CloseAsync

func (o OutputWriter) CloseAsync()

CloseAsync does nothing.

func (OutputWriter) Connected

func (o OutputWriter) Connected() bool

Connected always returns true.

func (OutputWriter) WaitForClose

func (o OutputWriter) WaitForClose(time.Duration) error

WaitForClose does nothing.

func (OutputWriter) WriteTransaction

func (o OutputWriter) WriteTransaction(ctx context.Context, t message.Transaction) error

WriteTransaction attempts to write a transaction to an output.

type Processor

type Processor func(*message.Batch) ([]*message.Batch, error)

Processor provides a mock processor implementation around a closure.

func (Processor) CloseAsync

func (p Processor) CloseAsync()

CloseAsync does nothing.

func (Processor) ProcessMessage

func (p Processor) ProcessMessage(b *message.Batch) ([]*message.Batch, error)

ProcessMessage returns the closure result executed on a batch.

func (Processor) WaitForClose

func (p Processor) WaitForClose(time.Duration) error

WaitForClose does nothing.

type RateLimit

type RateLimit func(context.Context) (time.Duration, error)

RateLimit provides a mock rate limit implementation around a closure.

func (RateLimit) Access

func (r RateLimit) Access(ctx context.Context) (time.Duration, error)

Access the rate limit

func (RateLimit) Close

func (r RateLimit) Close(ctx context.Context) error

Close does nothing

Jump to

Keyboard shortcuts

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