testutils

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NonExistentPathErrorMsg = "error in remove for path:"
	MissingPathErrorMsg     = "remove operation does not apply: doc is missing path"
)

Error messages to distinguish non-typed errors from the 'json-patch' library.

View Source
const (
	GlobalValuesKey = "global"
)

Variables

This section is empty.

Functions

func DecodeJSONPatchOperation

func DecodeJSONPatchOperation(v any) (patch.Operation, error)

func IsNonExistentPathError

func IsNonExistentPathError(err error) bool

func JSONPatchFromBytes

func JSONPatchFromBytes(data []byte) (patch.Patch, error)

func JSONPatchFromReader

func JSONPatchFromReader(r io.Reader) (patch.Patch, error)

func JSONPatchFromString

func JSONPatchFromString(in string) (patch.Patch, error)

func MergeMap

func MergeMap(dst, src map[string]any) map[string]any

MergeMap recursively merges the src and dst maps. Key conflicts are resolved by preferring src, or recursively descending, if both src and dst are maps.

func ValidateHookValuesPatch

func ValidateHookValuesPatch(valuesPatch ValuesPatch, permittedRootKey string) error

Types

type ApplyPatchMode

type ApplyPatchMode string
const (
	Strict                 ApplyPatchMode = "strict"
	IgnoreNonExistentPaths ApplyPatchMode = "ignore-non-existent-paths"
)

type Values

type Values map[string]any

Values stores values for modules or hooks by name.

func ApplyValuesPatch

func ApplyValuesPatch(values Values, valuesPatch ValuesPatch, mode ApplyPatchMode) (Values, bool, error)

ApplyValuesPatch uses patched jsonpatch library to make the behavior of ApplyIgnoreNonExistentPaths as fast as ApplyStrict. This function does not mutate input Values

type ValuesPatch

type ValuesPatch struct {
	Operations []*utils.ValuesPatchOperation
}

func AppendValuesPatch

func AppendValuesPatch(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch

func CompactPatches

func CompactPatches(existedOperations []*utils.ValuesPatchOperation, newOperations []*utils.ValuesPatchOperation) ValuesPatch

CompactPatches modifies an array of existed patch operations according to the new array of patch operations. The rule is: only last operation for the path should be stored.

func CompactValuesPatches

func CompactValuesPatches(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch

func EnabledFromValuesPatch

func EnabledFromValuesPatch(valuesPatch ValuesPatch) ValuesPatch

func FilterValuesPatch

func FilterValuesPatch(valuesPatch ValuesPatch, rootPath string) ValuesPatch

func NewValuesPatch

func NewValuesPatch() *ValuesPatch

func ValuesPatchFromBytes

func ValuesPatchFromBytes(data []byte) (*ValuesPatch, error)

ValuesPatchFromBytes reads a JSON stream of json patches and single operations from bytes and returns a ValuesPatch with all json patch operations. TODO do we need a separate utils.ValuesPatchOperation type??

func ValuesPatchFromFile

func ValuesPatchFromFile(filePath string) (*ValuesPatch, error)

func (*ValuesPatch) ApplyIgnoreNonExistentPaths

func (p *ValuesPatch) ApplyIgnoreNonExistentPaths(doc []byte) ([]byte, error)

ApplyIgnoreNonExistentPaths calls jsonpatch.Apply to transform an input JSON document.

- errors from "remove" operations are ignored.

func (*ValuesPatch) ApplyStrict

func (p *ValuesPatch) ApplyStrict(doc []byte) ([]byte, error)

ApplyStrict calls jsonpatch.Apply to transform a JSON document according to the patch.

- "remove" operation errors are not ignored. - absent paths are not ignored.

func (*ValuesPatch) MergeOperations

func (p *ValuesPatch) MergeOperations(src *ValuesPatch)

func (*ValuesPatch) ToJSONPatch

func (p *ValuesPatch) ToJSONPatch() (patch.Patch, error)

ToJSONPatch returns a jsonpatch.Patch with all operations.

Jump to

Keyboard shortcuts

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