testpayload

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowFileReads bool = false

AllowFileReads controls whether {{file:...}} placeholders are permitted. Disabled by default for safety; set via testpayload.SetAllowFileReads(true) or CLI flag.

View Source
var FileRoot string = ""

FileRoot is the optional root path for allowed file reads; empty means no root restriction.

Functions

func AddTemplateVar added in v1.1.0

func AddTemplateVar(name, val string)

AddTemplateVar adds a single template variable.

func ClearFileCache added in v1.1.0

func ClearFileCache()

ClearFileCache clears the in-memory file cache.

func ClearTemplateVars added in v1.1.0

func ClearTemplateVars()

ClearTemplateVars clears all configured template variables.

func GenerateCounter

func GenerateCounter() int

func GenerateNowDateTime

func GenerateNowDateTime() string

func GenerateRandomCBOR

func GenerateRandomCBOR() ([]byte, error)

GenerateRandomCBOR creates a CBOR with predictable structure and random values

func GenerateRandomDateTime

func GenerateRandomDateTime() string

func GenerateRandomJSON

func GenerateRandomJSON() ([]byte, error)

GenerateRandomJSON creates a JSON with predictable structure and random values

func GenerateSentence

func GenerateSentence() string

GenerateSentence generates a random sentence for tests

func GenerateSentimentPhrase

func GenerateSentimentPhrase() string

func GetFileFromCache added in v1.1.0

func GetFileFromCache(path string) ([]byte, bool)

GetFileFromCache returns file content if present, else nil/false

func Interpolate

func Interpolate(str string) ([]byte, error)

func InterpolateWithDelimiters

func InterpolateWithDelimiters(str string, openDelim string, closeDelim string) ([]byte, error)

InterpolateWithDelimiters performs template variable interpolation with custom delimiters Supports placeholders: json, cbor, sentiment, sentence, datetime, nowtime, counter, file:/path

func PutFileIntoCache added in v1.1.0

func PutFileIntoCache(path string, content []byte)

PutFileIntoCache stores content in the cache if enabled

func SeedRandom added in v1.1.0

func SeedRandom(seed int64)

SeedRandom seeds the global pseudo-random generator used by testpayload helpers. Useful to make generation deterministic for tests and reproducible scenarios.

func SetAllowFileReads added in v1.1.0

func SetAllowFileReads(v bool)

SetAllowFileReads toggles file reading support for the test payload generator.

func SetFileCacheEnabled added in v1.1.0

func SetFileCacheEnabled(v bool)

SetFileCacheEnabled toggles file content caching (process-lifetime cache).

func SetFileRoot added in v1.1.0

func SetFileRoot(root string)

SetFileRoot sets a root path that file placeholders must be under to be allowed.

func SetTemplateVars added in v1.1.0

func SetTemplateVars(vars map[string]string)

SetTemplateVars replaces the full variables map used by InterpolateWithDelimiters.

Types

type Payload

type Payload struct {
	ID     string  `faker:"uuid_hyphenated" json:"id"`
	Name   string  `faker:"name" json:"name"`
	Value  float64 `faker:"lat" json:"value"` // use lat as random float
	Active bool    `json:"active"`
	Time   int64   `faker:"unix_time" json:"time"`
}

Payload represents the predictable payload structure faker annotates fields for automatic generation https://github.com/go-faker/faker#supported-tags

type TestPayloadType

type TestPayloadType string
const (
	TestPayloadJSON      TestPayloadType = "json"
	TestPayloadCBOR      TestPayloadType = "cbor"
	TestPayloadSentiment TestPayloadType = "sentiment"
	TestPayloadSentence  TestPayloadType = "sentence"
	TestPayloadDateTime  TestPayloadType = "datetime" // to generate a timestamp
	TestPayloadNowTime   TestPayloadType = "nowtime"  // to generate the current timestamp
	TestPayloadCounter   TestPayloadType = "counter"  // to generate an incrementing counter (not implemented yet
)

func (TestPayloadType) Generate

func (t TestPayloadType) Generate() ([]byte, error)

func (TestPayloadType) GetContentType

func (t TestPayloadType) GetContentType() string

func (TestPayloadType) IsValid

func (t TestPayloadType) IsValid() bool

Jump to

Keyboard shortcuts

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