Documentation
¶
Index ¶
- Variables
- func AddTemplateVar(name, val string)
- func ClearFileCache()
- func ClearTemplateVars()
- func GenerateCounter() int
- func GenerateNowDateTime() string
- func GenerateRandomCBOR() ([]byte, error)
- func GenerateRandomDateTime() string
- func GenerateRandomJSON() ([]byte, error)
- func GenerateSentence() string
- func GenerateSentimentPhrase() string
- func GetFileFromCache(path string) ([]byte, bool)
- func Interpolate(str string) ([]byte, error)
- func InterpolateWithDelimiters(str string, openDelim string, closeDelim string) ([]byte, error)
- func PutFileIntoCache(path string, content []byte)
- func SeedRandom(seed int64)
- func SetAllowFileReads(v bool)
- func SetFileCacheEnabled(v bool)
- func SetFileRoot(root string)
- func SetTemplateVars(vars map[string]string)
- type Payload
- type TestPayloadType
Constants ¶
This section is empty.
Variables ¶
var AllowFileReads bool = false
AllowFileReads controls whether {{file:...}} placeholders are permitted. Disabled by default for safety; set via testpayload.SetAllowFileReads(true) or CLI flag.
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 ¶
GenerateRandomCBOR creates a CBOR with predictable structure and random values
func GenerateRandomDateTime ¶
func GenerateRandomDateTime() string
func GenerateRandomJSON ¶
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
GetFileFromCache returns file content if present, else nil/false
func Interpolate ¶
func InterpolateWithDelimiters ¶
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
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
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