datatest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T struct {
	testing.TB
}

T is the testing helper. Most notably it provides T.Equal

func New

func New(t testing.TB) T

func (T) Equal

func (is T) Equal(want, got any)

Equal reports whether want and got are deeply equal.

Unlike reflect.DeepEqual it first recursively checks exported fields and "getters", which are defined as an exported method with:

  • exactly zero input arguments
  • exactly one return value
  • does not start with 'Append'

If this yields differences, those are reported and the test fails. If the compared values are [pmetric.ExponentialHistogramDataPoint], then pmetrictest.CompareExponentialHistogramDataPoint is also called.

If no differences are found, it falls back to [assert.Equal].

This was done to aid readability when comparing deeply nested [pmetric]/[pcommon] types, because in many cases [assert.Equal] output was found to be barely understandable.

Example
is := datatest.New(t)

want := expotest.Histogram{
	PosNeg: expotest.Observe(expo.Scale(0), 1, 2, 3, 4),
	Scale:  0,
}.Into()

got := expotest.Histogram{
	PosNeg: expotest.Observe(expo.Scale(1), 1, 1, 1, 1),
	Scale:  1,
}.Into()

is.Equal(want, got)
Output:

equal_test.go:55: Negative().BucketCounts().AsRaw(): [1 1 2] != [4]
equal_test.go:55: Negative().BucketCounts().Len(): 3 != 1
equal_test.go:55: Positive().BucketCounts().AsRaw(): [1 1 2] != [4]
equal_test.go:55: Positive().BucketCounts().Len(): 3 != 1
equal_test.go:55: Scale(): 0 != 1

func (T) Equalf

func (is T) Equalf(want, got any, name string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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