testutils

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogMatcher = func(occurrences int, subStr string, logs []string) (bool, string) {
	errMsg := fmt.Sprintf("subStr '%s' does not occur %d time(s) in %v", subStr, occurrences, logs)
	if len(logs) < occurrences {
		return false, errMsg
	}
	var count int
	for _, log := range logs {
		if strings.Contains(log, subStr) {
			count++
		}
	}
	if count >= occurrences {
		return true, ""
	}
	return false, errMsg
}

LogMatcher is a helper func that returns true if the subStr appears more than 'occurrences' times in the logs.

Functions

func IgnoreGlogFlushDaemonLeak added in v1.53.0

func IgnoreGlogFlushDaemonLeak() goleak.Option

IgnoreGlogFlushDaemonLeak returns a goleak.Option that ignores the flushDaemon function from the glog package that can cause false positives in leak detection. This is necessary because glog starts a goroutine in the background that may not be stopped when the test finishes, leading to a detected but expected leak.

func IgnoreOpenCensusWorkerLeak added in v1.53.0

func IgnoreOpenCensusWorkerLeak() goleak.Option

IgnoreOpenCensusWorkerLeak This prevent catching the leak generated by opencensus defaultWorker.Start which at the time is part of the package's init call. See https://github.com/jaegertracing/jaeger/pull/5055#discussion_r1438702168 for more context.

func VerifyGoLeaks added in v1.54.0

func VerifyGoLeaks(m *testing.M)

VerifyGoLeaks verifies that unit tests do not leak any goroutines. It should be called in TestMain.

func VerifyGoLeaksOnce added in v1.54.0

func VerifyGoLeaksOnce(t *testing.T)

VerifyGoLeaksOnce verifies that a given unit test does not leak any goroutines. Occasionally useful to troubleshoot specific tests that are flaky due to leaks, since VerifyGoLeaks cannot distiguish which specific test caused the leak. It should be called via defer or from Cleanup:

defer testutils.VerifyGoLeaksOnce(t)

Types

type Buffer

type Buffer struct {
	sync.RWMutex
	zaptest.Buffer
}

Buffer wraps zaptest.Buffer and provides convenience method JSONLine(n)

func NewEchoLogger added in v1.21.0

func NewEchoLogger(t *testing.T) (*zap.Logger, *Buffer)

NewEchoLogger is similar to NewLogger, but the logs are also echoed to t.Log.

func NewLogger

func NewLogger() (*zap.Logger, *Buffer)

NewLogger creates a new zap.Logger backed by a zaptest.Buffer, which is also returned.

func (*Buffer) JSONLine

func (b *Buffer) JSONLine(n int) map[string]string

JSONLine reads n-th line from the buffer and converts it to JSON.

func (*Buffer) Lines

func (b *Buffer) Lines() []string

Lines overwrites zaptest.Buffer.Lines() to make it thread safe

func (*Buffer) String added in v1.1.0

func (b *Buffer) String() string

String overwrites zaptest.Buffer.String() to make it thread safe

func (*Buffer) Stripped

func (b *Buffer) Stripped() string

Stripped overwrites zaptest.Buffer.Stripped() to make it thread safe

func (*Buffer) Write

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

Write overwrites zaptest.Buffer.bytes.Buffer.Write() to make it thread safe

Jump to

Keyboard shortcuts

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