test

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package test contains utilities used in the policy engine's test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayIterationBenchmarkModule

func ArrayIterationBenchmarkModule(n int) string

ArrayIterationBenchmarkModule returns a module that iterates an array with `n` elements

func Eventually

func Eventually(t *testing.T, timeout time.Duration, f func() bool) bool

FIXME: Abort long running tests

func EventuallyOrFatal

func EventuallyOrFatal(t *testing.T, timeout time.Duration, f func() bool)

func GenerateConcurrencyBenchmarkData

func GenerateConcurrencyBenchmarkData() (string, map[string]any)

GenerateConcurrencyBenchmarkData returns a module and data; the module checks some input parameters against that data in a simple API authz scheme.

func GenerateJSONBenchmarkData

func GenerateJSONBenchmarkData(k, v int) map[string]any

GenerateJSONBenchmarkData returns a map of `k` keys and `v` key/value pairs.

func GenerateLargeJSONBenchmarkData

func GenerateLargeJSONBenchmarkData() map[string]any

GenerateLargeJSONBenchmarkData returns a map of 100 keys and 100.000 key/value pairs.

func GenerateVirtualDocsBenchmarkData

func GenerateVirtualDocsBenchmarkData(numTotalRules, numHitRules int) (string, map[string]any)

GenerateVirtualDocsBenchmarkData generates a module and input; the numTotalRules and numHitRules create as many rules in the module to match/miss the returned input.

func MakeTempFS

func MakeTempFS(root, prefix string, files map[string]string) (rootDir string, cleanup func(), err error)

MakeTempFS creates a temporary directory structure for test purposes rooted at root. If root is empty, the dir is created in the default system temp location. If the creation fails, cleanup is nil and the caller does not have to invoke it. If creation succeeds, the caller should invoke cleanup when they are done.

func ObjectIterationBenchmarkModule

func ObjectIterationBenchmarkModule(n int) string

ObjectIterationBenchmarkModule returns a module that iterates an object with `n` key/val pairs

func PartialObjectBenchmarkCrossModule

func PartialObjectBenchmarkCrossModule(n int) []string

PartialObjectBenchmarkCrossModule returns a module with n "bench_test_" prefixed rules that each refer to another "cond_bench_" prefixed rule

func PopulateAllFields added in v1.8.0

func PopulateAllFields[T any](t *testing.T) *T

PopulateAllFields uses reflection to populate all fields of a struct with test data. This is useful for testing code that must handle all fields but when new fields might be added and missed. It must be possible to set all fields, or the helper will fail until the fields are supported. Caveats: only supports types needed at time of implementation, will not work on recursive structs.

func SetIterationBenchmarkModule

func SetIterationBenchmarkModule(n int) string

SetIterationBenchmarkModule returns a module that iterates a set with `n` elements

func Skip

func Skip(*testing.T)

Skip will skip this test on pull request CI runs. Used for slow test runners on GHA's darwin machines.

func WithTempFS

func WithTempFS(files map[string]string, f func(string))

WithTempFS creates a temporary directory structure and invokes f with the root directory path.

func WithTestFS

func WithTestFS(files map[string]string, inMemoryFS bool, f func(string, fs.FS))

WithTestFS creates a temporary file system of `files` in memory if `inMemoryFS` is true and invokes `f“ with that filesystem

Types

type BlockingWriter

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

func (*BlockingWriter) Reset

func (w *BlockingWriter) Reset()

func (*BlockingWriter) String

func (w *BlockingWriter) String() string

func (*BlockingWriter) Write

func (w *BlockingWriter) Write(p []byte) (n int, err error)

type ZeroReader added in v1.2.0

type ZeroReader struct{}

ZeroReader is an io.Reader implementation that returns an infinite stream of zeros

func NewZeroReader added in v1.2.0

func NewZeroReader() *ZeroReader

NewZeroReader creates a new ZeroReader

func (ZeroReader) Read added in v1.2.0

func (ZeroReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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