testing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package testing is an extension to the standard go testing package tailored for testing the spine framework.

This package should solely be used by test packages.

Index

Constants

View Source
const (
	// TC is the TRACE log constant
	TC = "TRACE"
	// WN is the WARNING log constant
	WN = "WARN"
	// ER is the ERROR log constant
	ER = "ERRR"
)
View Source
const (
	OpCount = iota
	OpInc
	OpDec
	OpGauge
	OpTiming
	OpHistogram
)

Variables

This section is empty.

Functions

func DidPanic

func DidPanic(f func()) (bool, interface{})

DidPanic returns whether the given function panicked

func NewLogger

func NewLogger(t *testing.T, strict bool) log.Logger

NewLogger creates a new logger

func NewStats

func NewStats(t *testing.T) stats.Stats

NewStats creates a new stats

func NextPort

func NextPort() int

NextPort returns the next supposedly available port number

Types

type Logger

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

Logger is a simple Logger interface useful for tests

func (*Logger) AddCalldepth

func (l *Logger) AddCalldepth(n int) log.Logger

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Error

func (l *Logger) Error(tag, msg string, fields ...log.Field)

func (*Logger) Lines

func (l *Logger) Lines(s string) int

Lines returns the number of log lines for the given severity

func (*Logger) Trace

func (l *Logger) Trace(tag, msg string, fields ...log.Field)

func (*Logger) Warning

func (l *Logger) Warning(tag, msg string, fields ...log.Field)

func (*Logger) With

func (l *Logger) With(fields ...log.Field) log.Logger

type Stats

type Stats struct {
	Data map[string][]StatsPoint
	// contains filtered or unexported fields
}

Stats is a simple Stats interface useful for tests

func (*Stats) Count

func (s *Stats) Count(key string, n interface{}, meta ...map[string]string)

func (*Stats) Dec

func (s *Stats) Dec(key string, meta ...map[string]string)

func (*Stats) Gauge

func (s *Stats) Gauge(key string, n interface{}, meta ...map[string]string)

func (*Stats) Histogram

func (s *Stats) Histogram(key string, n interface{}, meta ...map[string]string)

func (*Stats) Inc

func (s *Stats) Inc(key string, meta ...map[string]string)

func (*Stats) Log added in v1.0.0

func (s *Stats) Log(l log.Logger) stats.Stats

func (*Stats) SetLogger

func (s *Stats) SetLogger(l log.Logger)

func (*Stats) Start

func (s *Stats) Start()

func (*Stats) Stop

func (s *Stats) Stop()

func (*Stats) Timing

func (s *Stats) Timing(key string, d time.Duration, meta ...map[string]string)

func (*Stats) With

func (s *Stats) With(meta map[string]string) stats.Stats

type StatsOp

type StatsOp int

StatsOp an operation, such as count, gauge, timing sent to the testing stats

type StatsPoint

type StatsPoint struct {
	Op   StatsOp
	N    interface{}
	Meta []map[string]string
}

type T

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

T is a wrapper of go standard testing.T It adds a few additional functions useful to spine

func New

func New(t *testing.T) *T

New returns a new instance of T

func (*T) Config

func (t *T) Config() *config.Config

Config returns an empty spine config

func (*T) DisableStrictMode

func (t *T) DisableStrictMode()

DisableStrictMode will stop making error logs failing a test

func (*T) Disco

func (t *T) Disco() disco.Agent

Disco returns a local service discovery agent

func (*T) Error

func (t *T) Error(args ...interface{})

Standard go testing.T functions

func (*T) Errorf

func (t *T) Errorf(format string, args ...interface{})

func (*T) Fail

func (t *T) Fail()

func (*T) FailNow

func (t *T) FailNow()

func (*T) Failed

func (t *T) Failed()

func (*T) Fatal

func (t *T) Fatal(args ...interface{})

func (*T) Fatalf

func (t *T) Fatalf(format string, args ...interface{})

func (*T) Log

func (t *T) Log(args ...interface{})

func (*T) Logf

func (t *T) Logf(format string, args ...interface{})

func (*T) Logger

func (t *T) Logger() log.Logger

Logger returns a spine logger interface

func (*T) Parallel

func (t *T) Parallel()

func (*T) Skip

func (t *T) Skip(args ...interface{})

func (*T) SkipNow

func (t *T) SkipNow()

func (*T) Skipf

func (t *T) Skipf(format string, args ...interface{})

func (*T) Skipped

func (t *T) Skipped()

func (*T) Stats

func (t *T) Stats() stats.Stats

Stats returns a spine stats interface

func (*T) WithCancel

func (t *T) WithCancel(parent context.Context) (context.Context, func())

WithCancel returns a new context

Jump to

Keyboard shortcuts

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