testutil

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectAllPaths

func CollectAllPaths(elem *etree.Element, parentPath string) []string

CollectAllPaths collects all unique element paths in the XML

func CompareDOMTrees

func CompareDOMTrees(original, marshaled *etree.Element, path string, comp *DOMComparison)

CompareDOMTrees recursively compares two XML DOM trees

func GenerateFieldCoverageReport

func GenerateFieldCoverageReport(t *testing.T, xmlPath string, validator RoundTripValidator)

GenerateFieldCoverageReport generates a detailed field coverage report using a custom validator

func GetTestFilePath

func GetTestFilePath(messageType, version, filename string) string

GetTestFilePath returns the full path to a test file (for non-embed usage)

func LoadTestFileFromFS

func LoadTestFileFromFS(t *testing.T, fsys embed.FS, filename string) []byte

LoadTestFileFromFS loads and returns the content of a test file from embedded FS

func Max

func Max(a, b int) int

Helper function for max

func RunConformanceTests

func RunConformanceTests(t *testing.T, messageType, version string, unmarshaler UnmarshalerFunc, validator ValidatorFunc)

RunConformanceTests runs conformance tests by dynamically scanning for test files

func RunConformanceTestsFS

func RunConformanceTestsFS(t *testing.T, fsys embed.FS, testFiles TestFileMap, unmarshaler UnmarshalerFunc, validator ValidatorFunc)

RunConformanceTestsFS runs conformance tests using embedded file system (legacy)

func RunConformanceTestsWithData

func RunConformanceTestsWithData(t *testing.T, testData map[string][]byte, unmarshaler UnmarshalerFunc, validator ValidatorFunc)

RunConformanceTestsWithData runs conformance tests using embedded data maps

func RunFieldCompletenessTests

func RunFieldCompletenessTests(t *testing.T, fsys embed.FS, testFiles TestFileMap, unmarshaler UnmarshalerFunc, fieldValidator func(*testing.T, interface{}, string))

RunFieldCompletenessTests runs tests to verify required fields are populated using embedded FS

func RunIntegrityTests

func RunIntegrityTests(t *testing.T, messageType, version string, validator RoundTripValidator)

RunIntegrityTests runs XML round-trip integrity tests with a custom validator

func RunMarshalingPerformanceTests

func RunMarshalingPerformanceTests(b *testing.B, messageType, version string, unmarshaler UnmarshalerFunc, marshaler func(interface{}) ([]byte, error))

RunMarshalingPerformanceTests runs performance benchmarks for marshaling by dynamically scanning for test files

func RunPerformanceTests

func RunPerformanceTests(b *testing.B, messageType, version string, unmarshaler UnmarshalerFunc)

RunPerformanceTests runs performance benchmarks for parsing by dynamically scanning for test files

func RunRoundTripPerformanceTests

func RunRoundTripPerformanceTests(b *testing.B, messageType, version string, unmarshaler UnmarshalerFunc, marshaler func(interface{}) ([]byte, error))

RunRoundTripPerformanceTests runs performance benchmarks for full round-trip operations by dynamically scanning for test files

func ValidateRequiredFields

func ValidateRequiredFields(t *testing.T, fields []FieldCheck)

ValidateRequiredFields validates that required fields are not nil/empty

Types

type DOMComparison

type DOMComparison struct {
	ElementsOriginal    int
	ElementsMarshaled   int
	AttributesOriginal  int
	AttributesMarshaled int
	MissingElements     []string
	MissingAttributes   []string
	ValueMismatches     []string
	ExtraElements       []string
	MarshaledParseable  bool // Can the marshaled XML be parsed back successfully
	Success             bool
}

DOMComparison holds the comparison results between two XML documents

func PerformRoundTripValidation

func PerformRoundTripValidation(xmlPath string, validator RoundTripValidator) *DOMComparison

PerformRoundTripValidation performs XML → Proto → XML validation with a custom validator

func PerformRoundTripValidationFromData

func PerformRoundTripValidationFromData(originalXML []byte, validator RoundTripValidator) *DOMComparison

PerformRoundTripValidationFromData performs XML → Proto → XML validation with a custom validator using byte data

type FieldCheck

type FieldCheck struct {
	Name  string
	Value interface{}
}

FieldCheck represents a field validation check

type RoundTripValidator

type RoundTripValidator func([]byte) ([]byte, error)

RoundTripValidator represents a function that can perform round-trip validation

type TestFileMap

type TestFileMap map[string]string

TestFileMap represents a map of test name to filename

type UnmarshalerFunc

type UnmarshalerFunc func([]byte) (interface{}, error)

UnmarshalerFunc represents a function that can unmarshal XML data to a message

type ValidatorFunc

type ValidatorFunc func(*testing.T, interface{}, string)

ValidatorFunc represents a function that validates a parsed message

Jump to

Keyboard shortcuts

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