testutils

package
v1.4.1-prerelease07 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultNilChance is the default probability of generating nil values
	DefaultNilChance = 0.3
	// DefaultIterations is the default number of fuzzing iterations
	DefaultIterations = 100
	// MaxSafeTimestampSeconds is the maximum safe Unix timestamp (year 2100)
	MaxSafeTimestampSeconds = 4102444800
	// NanosecondsPerSecond is the number of nanoseconds in a second
	NanosecondsPerSecond = 1000000000
	// MaxDurationSeconds is the maximum duration in seconds (24 hours)
	MaxDurationSeconds = 86400
)

Variables

This section is empty.

Functions

func EnsureFuzzCoverage

func EnsureFuzzCoverage(t *testing.T, expected []string, cb func(t *testing.T, f *fuzz.Fuzzer) string)

func RunMapperFuzzTest

func RunMapperFuzzTest[TInternal any, TExternal any](
	t *testing.T,
	fromFunc func(TInternal) TExternal,
	toFunc func(TExternal) TInternal,
	options ...FuzzOption,
)

RunMapperFuzzTest runs a fuzz test for a mapper pair (From/To functions). It generates random values, converts them through the mapper pair, and verifies the round-trip preserves the original value.

Example usage:

func TestActivityTypeFuzz(t *testing.T) {
    RunMapperFuzzTest(t, FromActivityType, ToActivityType)
}

Types

type FuzzOption

type FuzzOption func(*FuzzOptions)

FuzzOption is a functional option for configuring FuzzOptions

func WithCommonEnumFuzzers

func WithCommonEnumFuzzers() FuzzOption

WithCommonEnumFuzzers adds fuzzers for common Cadence enum types to ensure only valid enum values are generated

func WithCustomFuncs

func WithCustomFuncs(funcs ...interface{}) FuzzOption

WithCustomFuncs adds custom fuzzer functions for specific types

func WithDefaultFuzzers

func WithDefaultFuzzers() FuzzOption

WithDefaultFuzzers applies the standard set of fuzzers for time and common enums. This is applied automatically by RunMapperFuzzTest unless overridden.

func WithExcludedFields

func WithExcludedFields(fields ...string) FuzzOption

WithExcludedFields specifies field names to exclude from comparison

func WithIterations

func WithIterations(iterations int) FuzzOption

WithIterations sets the number of fuzzing iterations

func WithNilChance

func WithNilChance(chance float64) FuzzOption

WithNilChance sets the probability of generating nil values

func WithTimeFuzzers

func WithTimeFuzzers() FuzzOption

WithTimeFuzzers adds custom fuzzers for time.Time and time.Duration to ensure safe timestamp bounds and proper UTC normalization

type FuzzOptions

type FuzzOptions struct {
	// CustomFuncs are custom fuzzer functions to apply for specific types
	CustomFuncs []interface{}
	// ExcludedFields are field names to exclude from comparison (set to zero value)
	ExcludedFields []string
	// NilChance is the probability of setting pointer/slice fields to nil (default DefaultNilChance)
	NilChance float64
	// Iterations is the number of fuzzing iterations to run (default DefaultIterations)
	Iterations int
}

FuzzOptions configures the behavior of mapper fuzz tests

Jump to

Keyboard shortcuts

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