Documentation ¶
Overview ¶
package mxftest contains the test functions and interfaces for testing mxf/mrx files against their specifications. And for developing new tests for testing the mxf files.
Index ¶
- Constants
- func DecodeGroup(group *klv.KLV, primer map[string]string) (map[string]any, error)
- func DecodeGroupNode(doc io.ReadSeeker, node *Node, primer map[string]string) (map[string]any, error)
- func FullNameMask(key []byte, maskedBytes ...int) string
- func MRXTest(doc io.ReadSeeker, w io.Writer, testspecs ...Specifications) error
- func NodeToKLV(stream io.ReadSeeker, node *Node) (*klv.KLV, error)
- func ReferenceExtract(field any, reftype Ref) [][]byte
- func Sniff(data []byte, sniffers map[*DataIdentifier][]Sniffer) map[string]*SniffResult
- func WithNodeTags(nodeTags ...NodeTest) func(s *Specifications)
- func WithNodeTests(nodeTests ...NodeTest) func(s *Specifications)
- func WithPartitionTags(partitionTags ...PartitionTest) func(s *Specifications)
- func WithPartitionTests(partitionTests ...PartitionTest) func(s *Specifications)
- func WithSniffTest(sniffTest SniffTest) func(s *Specifications)
- func WithStructureTag(structureTags ...func(doc io.ReadSeeker, mxf *MXFNode) func(t Test)) func(s *Specifications)
- func WithStructureTests(structureTests ...func(doc io.ReadSeeker, mxf *MXFNode) func(t Test)) func(s *Specifications)
- type Assertions
- type CType
- type DataIdentifier
- type EssenceProperties
- type Expecter
- type GroupProperties
- type MXFAssertions
- func (e MXFAssertions) Error() types.Assertion
- func (e MXFAssertions) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) Shall(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) ShallNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
- func (e MXFAssertions) WithOffset(offset int) types.Assertion
- type MXFNode
- type MXFProperty
- type Node
- type NodeTest
- type Nodes
- type Parent
- type Partition
- type PartitionNode
- type PartitionProperties
- type PartitionTest
- type PartitionType
- type Position
- type RIP
- type Ref
- type Report
- type SniffContext
- type SniffResult
- type SniffTest
- type Sniffer
- type SnifferUpdate
- type SpecificationDetails
- type Specifications
- type Test
- type TestContext
- type TestResult
- type TestSection
- type Tester
Constants ¶
const ( // keys for identifying the type of partition. HeaderPartition = "header" BodyPartition = "body" GenericStreamPartition = "genericstreampartition" RIPPartition = "rip" )
const ( // ContentTypeKey is the key used for storing the ContentType of data from a sniff test. // It can be used with the node search functions ContentTypeKey = "ContentType" )
Variables ¶
This section is empty.
Functions ¶
func DecodeGroup ¶
DecodeGroup decodes a group KLV into a map[string]any, where the key of the map is the name of the field and the any is the decoded value. Any unknown fields will not be decoded and are skipped from the returned values.
The primer is a map of map[shorthandKey]fullUL
func DecodeGroupNode ¶
func DecodeGroupNode(doc io.ReadSeeker, node *Node, primer map[string]string) (map[string]any, error)
DecodeGroupNode decodes a Node into a map[string]any, where the key of the map is the name of the field and the any is the decoded value. Any unknown fields will not be decoded and are skipped from the returned values.
The primer is a map of map[shorthandKey]fullUL
func FullNameMask ¶
FullNameMask converts an array of 16 bytes into the universal label format of "%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x"
Any masked bytes are masked as 7f, and the maskbyte value is the integer position in the byte array (starting at 0).
func MRXTest ¶
func MRXTest(doc io.ReadSeeker, w io.Writer, testspecs ...Specifications) error
MRXTest tests an MRX file against the specifications given to it, if no specifications are passed then no tests are run. These test results are then logged as an yaml file to the io.Writer.
func ReferenceExtract ¶
ReferenceExtract extracts all references of a given type from a field. It returns each reference as the bytes. It looks at the type of the field and checks its name for the <reftype>Reference fields, if the field is not a reference object, then no references are returned.
This is for use with the github.com/metarex-media/mxf-to-go repository as it contains a large number of variables that are references or contain nested references. A switch statement would be unfeasible for every type and this is currently the next best thing.
func Sniff ¶
func Sniff(data []byte, sniffers map[*DataIdentifier][]Sniffer) map[string]*SniffResult
Sniff checks a stream of bytes to find the data type. it then performs any further sniff tests based on the type of data it finds, if it finds any data types that match. It stops searching after finding a data type that matches.
func WithNodeTags ¶
func WithNodeTags(nodeTags ...NodeTest) func(s *Specifications)
WithNodeTags adds the Node tests to the specifications object
func WithNodeTests ¶
func WithNodeTests(nodeTests ...NodeTest) func(s *Specifications)
WithNodeTests adds the Node tests to the specifications object
func WithPartitionTags ¶
func WithPartitionTags(partitionTags ...PartitionTest) func(s *Specifications)
WithPartitionTags adds the partition tests to the specification Tag
func WithPartitionTests ¶
func WithPartitionTests(partitionTests ...PartitionTest) func(s *Specifications)
WithPartitionTests adds the partition tests to the specification
func WithSniffTest ¶
func WithSniffTest(sniffTest SniffTest) func(s *Specifications)
WithSniffTest adds the SniffTest for the specification. That is the test that is run on any data found within the file.
func WithStructureTag ¶
func WithStructureTag(structureTags ...func(doc io.ReadSeeker, mxf *MXFNode) func(t Test)) func(s *Specifications)
WithStructureTag adds the tests to the specification tag.
func WithStructureTests ¶
func WithStructureTests(structureTests ...func(doc io.ReadSeeker, mxf *MXFNode) func(t Test)) func(s *Specifications)
WithStructureTests adds the structure tests to the specification. It does not check for repeats so make sure you do not repeat tests.
Types ¶
type Assertions ¶
type Assertions interface { Shall(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool ShallNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool types.Assertion }
Assertions wraps the gomega types assertions with the additional Shall and ShallNot assertion
type CType ¶
type CType string
CType is used for declaring content types of a data type. These are a separate type to make them easy to identify with autocomplete etc.
type DataIdentifier ¶
DataIdentifier contains the data type and function for checking if the data stream is that type.
type EssenceProperties ¶
type EssenceProperties struct {
EssUL string
}
EssenceProperties contains the properties of an essence object
func (EssenceProperties) ID ¶
func (e EssenceProperties) ID() string
ID returns the of the essence, it always returns ""
func (EssenceProperties) Label ¶
func (e EssenceProperties) Label() []string
Label returns the labels associated with the essence. it always returns []string{"essence"}
func (EssenceProperties) UL ¶
func (e EssenceProperties) UL() string
UL returns the Universal Label of the essence
type Expecter ¶
type Expecter interface {
Expect(actual interface{}, extra ...interface{}) Assertions
}
Expecter is a workaround to wrap the gomega/internal expect object
type GroupProperties ¶
GroupProperties contains the properties of an group object
func (GroupProperties) ID ¶
func (gp GroupProperties) ID() string
ID returns the of the group, formatted as "00000000.00000000.00000000.00000000"
func (GroupProperties) Label ¶
func (gp GroupProperties) Label() []string
Label returns an labels associated with a group
func (GroupProperties) UL ¶
func (gp GroupProperties) UL() string
UL returns the Universal Label of the group
type MXFAssertions ¶
type MXFAssertions struct {
// contains filtered or unexported fields
}
MXFAssertions wraps the basic types.assertions with some extra names to allow the MXf specification to be written as tests.
It satisfies the Assertions methods.
func (MXFAssertions) Error ¶
func (e MXFAssertions) Error() types.Assertion
func (MXFAssertions) NotTo ¶
func (e MXFAssertions) NotTo(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
func (MXFAssertions) Shall ¶
func (e MXFAssertions) Shall(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
Shall wraps the To assertion and behaves in the same way
func (MXFAssertions) ShallNot ¶
func (e MXFAssertions) ShallNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
ShallNot wraps the ToNot assertion and behaves in the same way
func (MXFAssertions) Should ¶
func (e MXFAssertions) Should(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
func (MXFAssertions) ShouldNot ¶
func (e MXFAssertions) ShouldNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
func (MXFAssertions) To ¶
func (e MXFAssertions) To(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
func (MXFAssertions) ToNot ¶
func (e MXFAssertions) ToNot(matcher types.GomegaMatcher, optionalDescription ...interface{}) bool
func (MXFAssertions) WithOffset ¶
func (e MXFAssertions) WithOffset(offset int) types.Assertion
type MXFNode ¶
type MXFNode struct { Partitions []*PartitionNode Tests tests[MXFNode] // contains filtered or unexported fields }
MXFNode is the parent node of the MXF file. it contains its partitions as children and the list of tests to run on the node.
func MakeAST ¶
func MakeAST(stream io.Reader, buffer chan *klv.KLV, size int, specs Specifications) (*MXFNode, error)
Make AST generates an Abstract Syntax Tree (AST) of an MXF file.
As part of the AST tests are assigned to the nodes in the tree, these tests are declared as specifications.
func (MXFNode) Search ¶
func (m MXFNode) Search(searchfield string) ([]*PartitionNode, error)
Search follows SQL for finding things within a partition e.g. select * from essence where partition <> header
Available tables are:
- partition
Available fields are:
- essence - the count of essence
- type - the partition types
- metadata - the count of metadata
Available operators are:
- AND - all conditions have to be true
The search command is not case sensitive
type MXFProperty ¶
type MXFProperty interface { // symbol returns the MXF UL associated with the node. // if there is one UL() string // ID returns the ID associated with the property ID() string // Returns the type of that node // e.g. essence, partition or the group type like Descriptivemetadata Label() []string }
MXFProperty contains the properties of and MXF object
type Node ¶
type Node struct {
Key, Length, Value Position
Properties MXFProperty
// talk through the children role with Bruce
// but keep as this
Tests tests[Node]
Children []*Node
Sniffs map[string]*SniffResult `yaml:"-"`
// contains filtered or unexported fields
}
Node is a object in the abstact syntax tree it can be a child, a parent or both.
func (*Node) FlagFail ¶
func (n *Node) FlagFail()
Flag fail sets the test pass to fail then calls the same on its parent.
func (Node) Search ¶
Search follows SQL syntax for nodes within a nodes children
e.g. select * where UL = 060e2b34.027f0101.0d010101.01010f00
"from" is not used as there are no tables within a node, the node is a table unto itself.
Available fields are:
- ul
- sniff:{field name} - e.g. sniff:/root searches the sniff value of root
The search command is not case sensitive
type NodeTest ¶
type NodeTest struct { // UL is the Universal Label of the Node being targeted. // e.g. 060e2b34.02530105.0e090502.00000000 // All Universal labels take this form UL string // The test function Test func(doc io.ReadSeeker, node *Node, primer map[string]string) func(t Test) }
NodeTest contains the key and a test for a partition test
type Nodes ¶
type Nodes interface { Node | PartitionNode | MXFNode }
Nodes are the different nodes in the Abstract syntax tree
type Parent ¶
type Parent interface {
FlagFail() // a function that recursively calls the parents when a test is failed
}
Parent is for declaring the parent of a node without out giving full control of that Node.
type Partition ¶
type Partition struct { Signature string // Must be, hex: 06 0E 2B 34 PartitionLength int // All but first block size MajorVersion uint16 // Must be, hex: 01 00 MinorVersion uint16 SizeKAG uint32 ThisPartition uint64 PreviousPartition uint64 HeaderByteCount uint64 IndexByteCount uint64 IndexSID uint32 BodyOffset uint64 BodySID uint32 // useful information from the partition PartitionType string IndexTable bool TotalHeaderLength int MetadataStart int }
Partition is the layout of an mxf partition with type accurate fields (or as close as possible)
func PartitionExtract ¶
PartitionExtract extracts the partition from a KLV packet
type PartitionNode ¶
type PartitionNode struct { Parent *MXFNode `yaml:"-"` Key, Length, Value Position HeaderMetadata []*Node Essence []*Node IndexTable *Node Props PartitionProperties Tests tests[PartitionNode] PartitionPos int // contains filtered or unexported fields }
PartitionNode is the node for every MXF partition/ It contains the different types of content as different arrays of nodes.
func (*PartitionNode) FlagFail ¶
func (p *PartitionNode) FlagFail()
Flag fail sets the test pass to fail then calls the same on its parent.
func (PartitionNode) Search ¶
func (p PartitionNode) Search(searchfield string) ([]*Node, error)
Search follows SQL syntax for nodes within a partition
e.g. select * from essence where UL <> 060e2b34.01020105.0e090502.017f017f
Available tables are:
- essence
- metadata
Available fields are:
- ul
- sniff:{field name} - e.g. sniff:/root searches the sniff value of root
The search command is not case sensitive
type PartitionProperties ¶
type PartitionProperties struct { PartitionCount int // the count of the partition along the MXF PartitionType string Primer map[string]string EssenceOrder []string }
PartitionProperties contains the properties of a partition object
func (PartitionProperties) ID ¶
func (p PartitionProperties) ID() string
ID returns the ID associated with a partition, it always returns ""
func (PartitionProperties) Label ¶
func (p PartitionProperties) Label() []string
Label returns the labels associated with the partition. it always returns []string{"partition"}
func (PartitionProperties) Symbol ¶
func (p PartitionProperties) Symbol() string
Symbol returns the type of the partition
type PartitionTest ¶
type PartitionTest struct { // PartitionType PartitionType // The test function Test func(doc io.ReadSeeker, partition *PartitionNode) func(t Test) }
PartitionTest contains the partition type and the test for a partition test. The partition types identifies the type of partition this test is targeting.
type PartitionType ¶
type PartitionType string
PartitionType is a string value of the partition type
const ( // The key used for identifying the header partition // it also flags footer partitions. Header PartitionType = "header" // the key for using identifying essence streams Body PartitionType = "essence" // The key used for identifying the Generic Body partition GenericBody PartitionType = "generickey" )
type Position ¶
type Position struct {
Start, End int
}
Position contains the start and end position of the Node in the byte stream.
type Report ¶
type Report struct { // Did the overall test pass TestPass bool // the tests and their results Tests []TestSection SkippedTests []skippedTest `yaml:"skippedTests,omitempty"` }
Report is the report structure of the MXF test report
type SniffContext ¶
type SniffContext struct {
// contains filtered or unexported fields
}
SniffContext is an array of bytes for preventing multiple sniff functions
func NewSniffContext ¶
func NewSniffContext() SniffContext
func (*SniffContext) CacheData ¶
func (s *SniffContext) CacheData(key, data any)
CacheData, caches a item in the sniff context, it can be retrieved with GetData()
func (*SniffContext) GetData ¶
func (s *SniffContext) GetData(key any) any
GetData returns the the data for a sniff context if no data is present a nil object is returned.
type SniffResult ¶
type SniffResult struct { // The sniff test key Key string // The sniff test result field Field string // The data of the sniff test Data CType // what certainty did the sniff test past as a % Certainty float64 }
SniffResult is the result of the sniff test.
type SniffTest ¶
type SniffTest struct { DataID DataIdentifier Sniffs []Sniffer }
SniffTest contains an identifier and the tests to run on any data that is identified.
type Sniffer ¶
type Sniffer *func(data []byte) SniffResult
Sniffer takes a stream of bytes, sniffs it (a quick look at the data) then returns a result of the sniff.
type SnifferUpdate ¶
type SnifferUpdate struct { Sniff func(data []byte) SniffResult SniffProperties props }
Sniffer takes a stream of bytes, sniffs it (a quick look at the data) then returns a result of the sniff.
type SpecificationDetails ¶
SpecificationDetails contains the information about the specification that made the test. It can be written with %s formatting
func NewSpecificationDetails ¶
func NewSpecificationDetails(docName, section, command string, commandCount int) SpecificationDetails
NewSpecificationDetails generates a new specificationDetails struct
func (SpecificationDetails) String ¶
func (s SpecificationDetails) String() string
String allows spec details to be written as a shorthand string
type Specifications ¶
type Specifications struct { // node specifications for groups, map is UL node test Node map[string][]markedTestWithPrimer[Node] // test aprtitions the partition tyoe is the map key Part map[string][]markedTest[PartitionNode] // array of mxf structural tests MXF []markedTest[MXFNode] // Sniff Tests to check the data SniffTests SniffTest // contains filtered or unexported fields }
Specifications contains all the information for a test specification.
It contains:
- The tests for each MXF Node
- Tags to ensure the specification runs on the correct files
- Data Sniff tests
These are all optional fields, a specification utilises as many or as few fields as required to validate the file.
func NewSpecification ¶
func NewSpecification(options ...func(*Specifications)) *Specifications
NewSpecification generates a new Specifications object. It is tailored to the options provided to generate custom specifications and the order in which the options are specified are the order in which the executed. If no options are provided and empty specifications object is returned. An empty specification is still a valid specification
type TestContext ¶
type TestContext struct {
// contains filtered or unexported fields
}
TestContext is the global context for all the MRX tests.
func NewTestContext ¶
func NewTestContext(dest io.Writer) *TestContext
NewTestContext generates a new testContext that writes to des.
ensure EndTest() is called to flush the results to the writer.
func (*TestContext) EndTest ¶
func (tc *TestContext) EndTest() error
EndTest flushes the tests as a complete yaml. End Test must be called to write the results to the io.Writer
func (*TestContext) Header ¶
func (s *TestContext) Header(message string, tests func(t Test))
Header is a wrapper for the tests, adding more context to the results, and then running the tests.
func (*TestContext) RegisterSkippedTest ¶
func (tc *TestContext) RegisterSkippedTest(key, desc string)
RegisterSkippedTest adds a skipped test to the test report.
type TestResult ¶
type TestResult struct { Message string Checks []check }
TestResult is the result of a test run
type TestSection ¶
type TestSection struct { // the header message for that batch of tests Header string // the tests themselves Tests []TestResult // the results Pass bool PassCount, FailCount int }
TestSection contains the information for a batch of tests
type Tester ¶
type Tester interface {
Test(message string, specDetail SpecificationDetails, asserts ...bool)
}
Tester is a workaround to wrap the gomega/internal test object
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package example contains example implementations of the mxftest repo
|
package example contains example implementations of the mxftest repo |
xmlhandle contains the xml data interactions, for using in sniff tests of MXF data.
|
xmlhandle contains the xml data interactions, for using in sniff tests of MXF data. |