test

package
v2.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoSomeLogging

func DoSomeLogging(cfg DoSomeLoggingCfg) (logged int32, filtered int32)

DoSomeLogging performs some concurrent logging on a preconfigured Logr.

func StringRnd

func StringRnd(length int) string

StringRnd returns a pseudo-random string of the specified length.

Types

type Buffer

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

Buffer is a simple thread-safe buffer implementing io.Writer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns buffer contents as a slice.

func (*Buffer) String

func (b *Buffer) String() string

String returns the buffer as a string.

func (*Buffer) Write

func (b *Buffer) Write(data []byte) (int, error)

Write adds data to the buffer.

type DoSomeLoggingCfg

type DoSomeLoggingCfg struct {
	// Lgr is a preconfigured Logr instance.
	Lgr *logr.Logr
	// Goroutines is number of goroutines to start.
	Goroutines int
	// Loops is number of loops per goroutine.
	Loops int
	// GoodToken is some text that is output for log statements that
	// should be output.
	GoodToken string
	// BadToken is text that is output for log statements that should be
	// filtered out.
	BadToken string
	// Lvl is the Level to use for log statements.
	Lvl logr.Level
	// Delay is amount of time to pause between loops.
	Delay time.Duration
}

DoSomeLoggingCfg is configuration for `DoSomeLogging` utility.

type FailingTarget

type FailingTarget struct {
}

FailingTarget is a test target that always fails.

func NewFailingTarget

func NewFailingTarget() *FailingTarget

NewFailingTarget creates a target that always fails.

func (*FailingTarget) Init

func (ft *FailingTarget) Init() error

func (*FailingTarget) Shutdown

func (ft *FailingTarget) Shutdown() error

func (*FailingTarget) Write

func (ft *FailingTarget) Write(p []byte, rec *logr.LogRec) (int, error)

Write simply fails.

type SlowTarget

type SlowTarget struct {
	Delay time.Duration
	// contains filtered or unexported fields
}

SlowTarget outputs log records to any `io.Writer` with configurable delay to simulate slower targets. Modify SlowTarget.Delay to determine the pause per log record.

func NewSlowTarget

func NewSlowTarget(out io.Writer, delayMillis int64) *SlowTarget

NewSlowTarget creates a new SlowTarget.

func (*SlowTarget) Init

func (st *SlowTarget) Init() error

func (*SlowTarget) Shutdown

func (st *SlowTarget) Shutdown() error

func (*SlowTarget) Write

func (st *SlowTarget) Write(p []byte, rec *logr.LogRec) (int, error)

Write after a delay.

type SocketServer

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

SocketServer is a simple socket server used for testing TCP log targets. Note: There is more synchronization here than normally needed to avoid flaky tests.

For example, it's possible for a unit test to create a SocketServer, attempt
writing to it, and stop the socket server before "go ss.listen()" gets scheduled.

func NewSocketServer

func NewSocketServer(port int, buf *Buffer) (*SocketServer, error)

func (*SocketServer) StopServer

func (ss *SocketServer) StopServer(wait bool) error

func (*SocketServer) WaitForAnyConnection

func (ss *SocketServer) WaitForAnyConnection() error

type TestCounter

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

func (*TestCounter) Add

func (c *TestCounter) Add(val float64)

func (*TestCounter) Inc

func (c *TestCounter) Inc()

type TestGauge

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

func (*TestGauge) Add

func (g *TestGauge) Add(val float64)

func (*TestGauge) Set

func (g *TestGauge) Set(val float64)

func (*TestGauge) Sub

func (g *TestGauge) Sub(val float64)

type TestMetrics

type TestMetrics struct {
	QueueSize float64
	Logged    float64
	Errors    float64
	Dropped   float64
	Blocked   float64
}

type TestMetricsCollector

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

func NewTestMetricsCollector

func NewTestMetricsCollector() *TestMetricsCollector

func (*TestMetricsCollector) BlockedCounter

func (c *TestMetricsCollector) BlockedCounter(target string) (logr.Counter, error)

func (*TestMetricsCollector) DroppedCounter

func (c *TestMetricsCollector) DroppedCounter(target string) (logr.Counter, error)

func (*TestMetricsCollector) ErrorCounter

func (c *TestMetricsCollector) ErrorCounter(target string) (logr.Counter, error)

func (*TestMetricsCollector) Get

func (c *TestMetricsCollector) Get(target string) TestMetrics

func (*TestMetricsCollector) LoggedCounter

func (c *TestMetricsCollector) LoggedCounter(target string) (logr.Counter, error)

func (*TestMetricsCollector) QueueSizeGauge

func (c *TestMetricsCollector) QueueSizeGauge(target string) (logr.Gauge, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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