Back to godoc.org

Package testutils

v1.15.1
Latest Go to latest

The highest tagged major version is .

Published: Nov 7, 2019 | License: Apache-2.0 | Module: github.com/Hoggles/TraceAI

Index

Variables

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.

type Buffer

type Buffer struct {
	sync.RWMutex
	zaptest.Buffer
}

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

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

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier