match

package
v0.37.0 Latest Latest
Warning

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

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

Documentation

Overview

Package match provides various helper functions for matching actual output to expected output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualString added in v0.30.0

func EqualString(t *testing.T, expectedString string) func(t *testing.T, output string)

EqualString verifies that the output string matches the expectedString. This function can be directly used as ValidateOutput function.

func MatchAllEntries added in v0.30.0

func MatchAllEntries[T any](t *testing.T, outputMode OutputMode, output string, normalize func(*T), expectedEntry *T)

MatchAllEntries verifies that expectedEntry is matched by all entries in the output. The output is parsed according to outputMode.

func MatchEntries added in v0.30.0

func MatchEntries[T any](t *testing.T, outputMode OutputMode, output string, normalize func(*T), expectedEntries ...*T)

MatchEntries verifies that all the entries in expectedEntries are matched by at least one entry in the output. The output is parsed according to outputMode.

func MatchRegexp added in v0.30.0

func MatchRegexp(t *testing.T, expectedRegexp string) func(t *testing.T, output string)

MatchRegexp verifies that the output string matches the expected regular expression. This function can be directly used as ValidateOutput function.

func MatchUnmarshalledEntries added in v0.30.0

func MatchUnmarshalledEntries[T any](t *testing.T, entries []*T, expectedEntries ...*T)

MatchUnmarshalledEntries verifies that all the entries in expectedEntries are matched by at least one entry in entries. MatchUnmarshalledEntries([]int{1, 2, 3}, 2, 3) will pass MatchUnmarshalledEntries([]int{1, 2, 3}, 2, 4) will fail

Types

type OutputMode added in v0.30.0

type OutputMode int

OutputMode represents how the output string should be parsed.

const (
	InvalidMode OutputMode = iota

	// JSONSingleObjectMode represents the mode in which the output is single
	// JSON object.
	//
	// Example: One object in one line:
	// {"key": "value1", "key2": "value4"}
	//
	// Example: Object spread across multiple lines:
	//{
	//	"key": "value1",
	//	"key2": "value4"
	//}
	//
	// Currently not known gadget produces this output.
	JSONSingleObjectMode

	// JSONMultiObjectMode represents the mode in which the output is one or multiple
	// JSON objects.
	//
	// Example: One object per line:
	// {"key": "value1", "key2": "value4"}
	// {"key": "value2", "key2": "value5"}
	// {"key": "value3", "key2": "value6"}
	//
	// Example: Object spread across multiple lines:
	//{
	//	"key": "value1",
	//	"key2": "value4"
	//}
	//{
	//	"key": "value2",
	//	"key2": "value5"
	//}
	//{
	//	"key": "value3",
	//	"key2": "value6"
	//}
	//
	// This output is produced by gadgets like trace_open, trace_exec, etc.
	JSONMultiObjectMode

	// JSONSingleArrayMode represents the mode in which the output a single JSON
	// array.
	//
	// Example: Single array in one line:
	// [{"key": "value1"}, {"key": "value2"}, {"key": "value3"}]
	//
	// Example: Single array in multiple lines:
	// [
	// 	{
	// 		"key": "value1"
	// 	},
	// 	{
	// 		"key": "value2"
	// 	},
	// 	{
	// 		"key": "value3"
	// 	}
	// ]
	//
	// This output is produced by gadgets like snapshot_process, snapshot_socket, etc.
	JSONSingleArrayMode

	// JSONMultiArrayMode represents the mode in which the output is one or multiple
	// JSON arrays.
	//
	// Example: Multiple arrays, one per line:
	// [{"key": "value1"}, {"key": "value2"}, {"key": "value3"}]
	// [{"key": "value4"}, {"key": "value5"}, {"key": "value4"}]
	//
	// Example: Multiple arrays, in multiple lines:
	// [
	// 	{
	// 		"key": "value1"
	// 	},
	// 	{
	// 		"key": "value2"
	// 	},
	// 	{
	// 		"key": "value3"
	// 	}
	// ]
	// [
	// 	{
	// 		"key": "value4"
	// 	},
	// 	{
	// 		"key": "value5"
	// 	},
	// 	{
	// 		"key": "value4"
	// 	}
	// ]
	//
	// This output is produced by gadgets like top_file, top_tcp, etc.
	JSONMultiArrayMode
)

Jump to

Keyboard shortcuts

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