assert

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

README

This package supports validation of data that has passed through Arrow encoding and decoding, recognizing that there may be structural differences for semantically equivalent data.

Examples of transformations that are allowed by assert.Equiv():

  • Appearance of duplicate Resource, Scope, and Metric entities
  • Order of Resource instances in a Resource list
  • Order of Scope items in a Resource
  • Order of Span, Metric, and LogRecord items in a Scope
  • Order of Links/Events in a Span
  • and so on.

The assert.Equiv() method in this package should be used for unittesting and validation of data in an OTel Arrow pipeline. See the code for details.

Documentation

Overview

Package assert provides a set of helper functions to assert conditions in OTLP Arrow tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalMapID

func CanonicalMapID(object map[string]interface{}) string

CanonicalMapID computes a unique ID for a map. Sort the keys to ensure a consistent order.

func CanonicalObjectID

func CanonicalObjectID(object interface{}) string

CanonicalObjectID computes a unique ID for an object.

func CanonicalSliceID

func CanonicalSliceID(slice []interface{}) string

CanonicalSliceID computes a unique ID for a slice.

func CanonicalSliceMapID

func CanonicalSliceMapID(slice []map[string]interface{}) string

CanonicalSliceMapID computes a unique ID for a slice of maps.

func Equiv

func Equiv(t Testing, expected []json.Marshaler, actual []json.Marshaler)

Equiv asserts that two arrays of json.Marshaler are equivalent. Metrics, logs, and traces requests implement json.Marshaler and are considered equivalent if they have the same set of vPaths. A vPath is a path to a value in a json object. For example the vPath "resource.attributes.service.name=myservice" refers to the value "myservice" in the json object {"resource":{"attributes":{"service":{"name":"myservice"}}}}.

The structure of the expected and actual json objects does not need to be exactly the same. For example, the following json objects are considered equivalent: [{"resource":{"attributes":{"service":"myservice", "version":"1.0"}}}] [{"resource":{"attributes":{"service":"myservice"}}}, {"resource":{"attributes":{"version":"1.0"}}}]

This concept of equivalence is useful for testing the conversion OTLP to/from OTLP Arrow as this conversion doesn't necessarily preserve the structure of the original OTLP entity. Resource spans or scope spans can be split or merged during the conversion if the semantic is preserved.

func EquivFromBytes

func EquivFromBytes(t Testing, expected []byte, actual []byte)

func JSONCanonicalEq

func JSONCanonicalEq(t Testing, expected interface{}, actual interface{})

JSONCanonicalEq compares two JSON objects for equality after converting them to a canonical form. This is useful for comparing JSON objects that may have different key orders or array orders.

func NotEquiv

func NotEquiv(t Testing, expected []json.Marshaler, actual []json.Marshaler)

NotEquiv asserts that two arrays of json.Marshaler are not equivalent. See Equiv for the definition of equivalence.

Types

type StandaloneTest

type StandaloneTest struct {
}

StandaloneTest adapts the Equiv() method for a standard unit test.

func (*StandaloneTest) Equal

func (a *StandaloneTest) Equal(expected, actual interface{}, msgAndArgs ...any) bool

func (*StandaloneTest) FailNow

func (a *StandaloneTest) FailNow(failureMessage string, msgAndArgs ...any) bool

func (*StandaloneTest) Helper

func (a *StandaloneTest) Helper()

func (*StandaloneTest) NoError

func (a *StandaloneTest) NoError(err error, msgAndArgs ...any)

type StdUnitTest

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

StdUnitTest adapts the Equiv() method for a standard unit test.

func (*StdUnitTest) Equal

func (a *StdUnitTest) Equal(expected, actual interface{}, msgAndArgs ...any) bool

func (*StdUnitTest) FailNow

func (a *StdUnitTest) FailNow(failureMessage string, msgAndArgs ...any) bool

func (*StdUnitTest) Helper

func (a *StdUnitTest) Helper()

func (*StdUnitTest) NoError

func (a *StdUnitTest) NoError(err error, msgAndArgs ...any)

type Testing

type Testing interface {
	Helper()
	FailNow(failureMessage string, msgAndArgs ...any) bool
	NoError(err error, msgAndArgs ...any)
	Equal(expected, actual interface{}, msgAndArgs ...any) bool
}

Testing is an interface that makes `assert.Equiv` independent of the testing framework. It is then possible to use `assert.Equiv` in contexts where the testing framework is not available.

func NewStandaloneTest

func NewStandaloneTest() Testing

func NewStdUnitTest

func NewStdUnitTest(t *testing.T) Testing

Jump to

Keyboard shortcuts

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