Documentation
¶
Overview ¶
Package jsontest provides a comprehensive JSON testing framework with declarative assertions and pipe functions. It supports path-based JSON validation, array handling, pipe transformations, and sophisticated comparison logic.
Package jsontest provides pipe function infrastructure for JSON assertion testing. Pipe functions allow transformation and validation of JSON values during test processing.
Package jsontest provides the core TestJSON function and path classification logic. This file contains the main public API for JSON assertion testing with path-based validation.
Package jsontest defines marker types and helper types for JSON assertion testing. This file contains types for controlling comparison behavior and order-insensitive testing.
Index ¶
- func GetRegisteredPipeFuncNames() []string
- func IsJSONObject(r gjson.Result) bool
- func RegisterPipeFunc(pf PipeFunc)
- func RegisteredPipeFuncMap() (m map[string]PipeFunc)
- func TestJSON(data []byte, checks map[string]any) (err error)
- type AnyOrderSlice
- type BasePipeFunc
- type NotEmpty
- type NotNull
- type PipeFunc
- type PipeState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRegisteredPipeFuncNames ¶
func GetRegisteredPipeFuncNames() []string
GetRegisteredPipeFuncNames returns the names of all registered PipeFunc
func IsJSONObject ¶
IsJSONObject inspects a gjson.Result to determine if it is JSON within a string
func RegisterPipeFunc ¶
func RegisterPipeFunc(pf PipeFunc)
RegisterPipeFunc adds a pipe function to the global registry. The function name must end with "()" to indicate it's callable.
func RegisteredPipeFuncMap ¶
RegisteredPipeFuncMap returns a map of pipe function names to PipeFunc instance RegisteredPipeFuncMap returns a map of pipe function names to PipeFunc instances for efficient lookup by name.
Types ¶
type AnyOrderSlice ¶
type AnyOrderSlice[T comparable] []T
AnyOrderSlice is a named slice type used to signal order-insensitive comparison.
func AnyOrder ¶
func AnyOrder[T comparable](vals ...T) AnyOrderSlice[T]
AnyOrder creates an AnyOrderSlice from the provided values, allowing order-insensitive comparison in JSON assertions.
type BasePipeFunc ¶
type BasePipeFunc struct {
// contains filtered or unexported fields
}
BasePipeFunc provides common functionality for all pipe functions.
func NewBasePipeFunc ¶
func NewBasePipeFunc(name string) BasePipeFunc
NewBasePipeFunc creates a new BasePipeFunc with the given name. The name is normalized to lowercase and trimmed of whitespace.
func (BasePipeFunc) Name ¶
func (pf BasePipeFunc) Name() string
Name returns the normalized name of the pipe function Name returns the normalized name of the pipe function.
func (BasePipeFunc) PipeFunc ¶
func (pf BasePipeFunc) PipeFunc()
PipeFunc implements the PipeFunc interface marker method.
type NotEmpty ¶
type NotEmpty struct{}
NotEmpty is a marker type used in JSON assertions to indicate that a value must not be empty (non-zero, non-empty string, etc.).
type NotNull ¶
type NotNull struct{}
NotNull is a marker type used in JSON assertions to indicate that a value must not be null.
type PipeFunc ¶
PipeFunc represents a function that can be used in JSON test pipe operations. Pipe functions validate or transform JSON values during assertion processing.
func GetRegisteredPipeFunc ¶
GetRegisteredPipeFunc finds a registered pipe function by name (case-insensitive). Returns nil if no pipe function with the given name is found.
func RegisteredPipeFuncs ¶
func RegisteredPipeFuncs() []PipeFunc
RegisteredPipeFuncs returns a slice of all registered pipe functions.