approvaltest

package
v0.0.0-...-d081dba Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package approvaltest contains helper functions to compare and assert the received content of a test vs the accepted.

Index

Constants

View Source
const (
	// ApprovedSuffix signals a file has been reviewed and approved.
	ApprovedSuffix = ".approved.json"

	// ReceivedSuffix signals a file has changed and not yet been approved.
	ReceivedSuffix = ".received.json"
)

Variables

This section is empty.

Functions

func ApproveEvents

func ApproveEvents(t testing.TB, name string, hits []espoll.SearchHit, dynamic ...string)

ApproveEvents compares the _source of the search hits with the contents of the file in "approvals/<name>.approved.json".

Dynamic fields (@timestamp, observer.id, etc.) are replaced with a static string for comparison. Integration tests elsewhere use canned data to test fields that we do not cover here.

If the events differ, then the test will fail.

func ApproveFields

func ApproveFields(t testing.TB, name string, hits []espoll.SearchHit, dynamic ...string)

ApproveFields compares the fields of the search hits with the contents of the file in "approvals/<name>.approved.json".

Dynamic fields (@timestamp, observer.id, etc.) are replaced with a static string for comparison. Integration tests elsewhere use canned data to test fields that we do not cover here.

TODO(axw) eventually remove ApproveEvents when we have updated all calls to use ApproveFields. ApproveFields should be used since it includes runtime fields, whereas ApproveEvents only looks at _source.

func ApproveFieldsSource

func ApproveFieldsSource(t testing.TB, name string, hits []espoll.SearchHit, dynamic ...string)

ApproveFieldsSource compares the merged fields and _source values of the search hits with the contents of the file in "approvals/<name>.approved.json".

Dynamic fields (@timestamp, observer.id, etc.) are replaced with a static string for comparison. Integration tests elsewhere use canned data to test fields that we do not cover here.

Unlike ApproveFields, this includes non-indexed values from _source. If a field exists in both fields and _source, fields takes precedence.

Types

This section is empty.

Jump to

Keyboard shortcuts

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