test

package
v0.0.0-...-45cd8ed Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(t testing.TB, src, dst string)

func EqualSlices

func EqualSlices[T any](expected, actual []T) assert.Comparison

EqualSlices is a comparison function for slices that treats nil slices as equivalent to empty slices (which the assert.Equals assertion does not).

func GenerateTestFloatHistogram

func GenerateTestFloatHistogram(i int) *histogram.FloatHistogram

func GenerateTestFloatHistograms

func GenerateTestFloatHistograms(i int) []*histogram.FloatHistogram

func GenerateTestGaugeFloatHistogram

func GenerateTestGaugeFloatHistogram(i int) *histogram.FloatHistogram

func GenerateTestGaugeHistogram

func GenerateTestGaugeHistogram(i int) *histogram.Histogram

func GenerateTestHistogram

func GenerateTestHistogram(i int) *histogram.Histogram

func GenerateTestHistograms

func GenerateTestHistograms(i int) []*histogram.Histogram

func GenerateTestSampleHistogram

func GenerateTestSampleHistogram(i int) *model.SampleHistogram

explicit decoded version of GenerateTestHistogram and GenerateTestFloatHistogram

func RequireFloatHistogramEqual

func RequireFloatHistogramEqual(t require.TestingT, expected, actual *histogram.FloatHistogram, msgAndArgs ...interface{})

RequireFloatHistogramEqual requires the two float histograms to be equal.

func RequireHistogramEqual

func RequireHistogramEqual(t require.TestingT, expected, actual *histogram.Histogram, msgAndArgs ...interface{})

RequireHistogramEqual requires the two histograms to be equal.

func RequireIteratorFloat

func RequireIteratorFloat(t *testing.T, expectedTs int64, expectedV float64, iter chunkenc.Iterator, valueType chunkenc.ValueType)

RequireIteratorFloat checks that the iterator contains the expected float value and type at the position.

func RequireIteratorFloatHistogram

func RequireIteratorFloatHistogram(t *testing.T, expectedTs int64, expectedV *histogram.FloatHistogram, iter chunkenc.Iterator, valueType chunkenc.ValueType)

RequireIteratorFloatHistogram checks that the iterator contains the expected float histogram value and type at the position.

func RequireIteratorHistogram

func RequireIteratorHistogram(t *testing.T, expectedTs int64, expectedV *histogram.Histogram, iter chunkenc.Iterator, valueType chunkenc.ValueType)

RequireIteratorHistogram checks that the iterator contains the expected histogram value and type at the position. Also test automatic conversion to float histogram.

func RequireIteratorIthFloat

func RequireIteratorIthFloat(t *testing.T, i int64, iter chunkenc.Iterator, valueType chunkenc.ValueType)

func RequireIteratorIthFloatHistogram

func RequireIteratorIthFloatHistogram(t *testing.T, i int64, iter chunkenc.Iterator, valueType chunkenc.ValueType)

func RequireIteratorIthHistogram

func RequireIteratorIthHistogram(t *testing.T, i int64, iter chunkenc.Iterator, valueType chunkenc.ValueType)

func RequireSameShape

func RequireSameShape(t *testing.T, expectedType, actualType any, ignoreName bool, ignoreXXXPrefix bool)

We use unsafe casting to convert between some Mimir and Prometheus types For this to be safe, the two types need to have the same shape (same fields in the same order). This function requires that this property is maintained. The fields do not need to have the same names to make the conversion safe, but we also check the names are the same here to ensure there's no confusion (eg. two bool fields swapped) when ignoreName is false. However, when you know the names are different, you can set ignoreName to true. The ignoreXXXPrefix flag is used to ignore fields with the XXX_ prefix.

func VerifyNoLeak

func VerifyNoLeak(t testing.TB, extraOpts ...goleak.Option)

func VerifyNoLeakTestMain

func VerifyNoLeakTestMain(m *testing.M, extraOpts ...goleak.Option)

Types

type CapturedOutput

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

func CaptureOutput

func CaptureOutput(t *testing.T) *CapturedOutput

CaptureOutput replaces os.Stdout and os.Stderr with new pipes, that will write output to buffers. Buffers are accessible by calling Done on returned struct.

os.Stdout and os.Stderr must be reverted to previous values manually.

func (*CapturedOutput) Done

func (co *CapturedOutput) Done() (stdout string, stderr string)

Done waits until all captured output has been written to buffers, and then returns the buffers.

type CollectWithLogf

type CollectWithLogf struct {
	*assert.CollectT
}

func NewCollectWithLogf

func NewCollectWithLogf(collectT *assert.CollectT) *CollectWithLogf

func (*CollectWithLogf) Logf

func (c *CollectWithLogf) Logf(_ string, _ ...interface{})

type ExpectedMetrics

type ExpectedMetrics struct {
	Context ExpectedMetricsContext
	Output  []string
	Names   []string
}

func (*ExpectedMetrics) Add

func (m *ExpectedMetrics) Add(name, labelSet string, count int)

func (*ExpectedMetrics) AddEmpty

func (m *ExpectedMetrics) AddEmpty(name string)

func (*ExpectedMetrics) AddMultiple

func (m *ExpectedMetrics) AddMultiple(name string, counts map[string]int)

func (*ExpectedMetrics) GetNames

func (m *ExpectedMetrics) GetNames() []string

func (*ExpectedMetrics) GetOutput

func (m *ExpectedMetrics) GetOutput() io.Reader

type ExpectedMetricsContext

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

func NewExpectedMetricsContext

func NewExpectedMetricsContext() ExpectedMetricsContext

func (*ExpectedMetricsContext) Add

func (m *ExpectedMetricsContext) Add(name, help, types string)

type TB

type TB interface {
	testing.TB
	IsBenchmark() bool
	Run(name string, f func(t TB)) bool

	SetBytes(n int64)
	N() int
	ResetTimer()
}

TB represents union of test and benchmark. This allows the same test suite to be run by both benchmark and test, helping to reuse more code. The reason is that usually benchmarks are not being run on CI, especially for short tests, so you need to recreate usually similar tests for `Test<Name>(t *testing.T)` methods. Example of usage is presented here:

 func TestTestOrBench(t *testing.T) {
	tb := NewTB(t)
	tb.Run("1", func(tb TB) { testorbenchComplexTest(tb) })
	tb.Run("2", func(tb TB) { testorbenchComplexTest(tb) })
}

func BenchmarkTestOrBench(b *testing.B) {
	tb := NewTB(t)
	tb.Run("1", func(tb TB) { testorbenchComplexTest(tb) })
	tb.Run("2", func(tb TB) { testorbenchComplexTest(tb) })
}

func NewTB

func NewTB(t testing.TB) TB

NewTB creates tb from testing.TB.

type TestingLogger

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

func NewTestingLogger

func NewTestingLogger(t testing.TB) *TestingLogger

func (*TestingLogger) Log

func (l *TestingLogger) Log(keyvals ...interface{}) error

func (*TestingLogger) WithT

func (l *TestingLogger) WithT(t testing.TB) log.Logger

WithT returns a new logger that logs to t. Writes between the new logger and the original logger are synchronized.

Jump to

Keyboard shortcuts

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