Documentation ¶
Overview ¶
Package testutil contains a set of utilities that are useful within tests of ygot-related data.
Index ¶
- func GenerateUnifiedDiff(want, got string) (string, error)
- func GetResponseEqual(a, b *gnmipb.GetResponse, opts ...ComparerOpt) bool
- func JSONIETFComparer(a, b []byte) bool
- func NotificationComparer() cmp.Option
- func NotificationLess(a, b *gnmipb.Notification) bool
- func NotificationSetEqual(a, b []*gnmipb.Notification, opts ...ComparerOpt) bool
- func PathLess(a, b *gnmipb.Path) bool
- func SubscribeResponseEqual(a, b *gnmipb.SubscribeResponse) bool
- func SubscribeResponseSetEqual(a, b []*gnmipb.SubscribeResponse) bool
- func UpdateLess(a, b *gnmipb.Update) bool
- func UpdateSetEqual(a, b []*gnmipb.Update) bool
- type Binary
- type ComparerOpt
- type CustomComparer
- type IgnoreTimestamp
- type TestUnion
- type TestUnion2
- type UnionBool
- type UnionFloat64
- type UnionInt16
- type UnionInt32
- type UnionInt64
- type UnionInt8
- type UnionString
- type UnionUint16
- type UnionUint32
- type UnionUint64
- type UnionUint8
- type UnionUnsupported
- type YANGEmpty
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateUnifiedDiff ¶
GenerateUnifiedDiff takes two strings and generates a diff that can be shown to the user in a test error message.
func GetResponseEqual ¶
func GetResponseEqual(a, b *gnmipb.GetResponse, opts ...ComparerOpt) bool
GetResponseEqual compares the contents of a and b and returns true if they are equal. Extensions in the GetResponse are ignored. The supplied ComparerOpt options are used to influnce the equality comparison between a and b.
func JSONIETFComparer ¶
JSONIETFComparer compares the two provided JSON IETF TypedValues to determine whether their contents are the same. If either value is invalid JSON, the function returns false.
func NotificationComparer ¶ added in v0.29.0
NotificationComparer returns a cmp.Option that can be used to compare two gnmipb.Notification messages where the order of updates and deletes are not significant.
func NotificationLess ¶
func NotificationLess(a, b *gnmipb.Notification) bool
NotificationLess compares the two notifications a and b, returning true if a is less than b, and false if not. Less is defined by:
- Comparing the timestamp.
- If equal timestamps, comparing the prefix using PathLess.
- If equal prefixes, comparing the Updates using UpdateLess.
- If equal updates, comparing the Deletes using deleteLess.
If all fields are equal, the function returns false to ensure that the irreflexive property required by cmpopts.SortSlices is implemented.
func NotificationSetEqual ¶
func NotificationSetEqual(a, b []*gnmipb.Notification, opts ...ComparerOpt) bool
NotificationSetEqual compares the contents of a and b and returns true if they are equal. Order of the slices is ignored. The set of ComparerOpts supplied are used to influnce the equality comparison between members of a and b.
func PathLess ¶
PathLess provides a function which determines whether a gNMI Path messages A is less than the gNMI Path message b. It can be used to allow sorting of gNMI path messages - for example, in cmpopts.SortSlices.
func SubscribeResponseEqual ¶
func SubscribeResponseEqual(a, b *gnmipb.SubscribeResponse) bool
SubscribeResponseEqual compares the contents of a and b and returns true if they are equal. Extensions in the SubscribeResponse are ignored.
func SubscribeResponseSetEqual ¶
func SubscribeResponseSetEqual(a, b []*gnmipb.SubscribeResponse) bool
SubscribeResponseSetEqual compares the contents of the slices of SubscribeResponse messages in a and b and returns true if they are equal. Order of the slices is ignored.
func UpdateLess ¶
UpdateLess compares two gNMI Update messages and returns true if a < b. The less-than comparison is done by first comparing the paths of the updates, and subquently comparing the typedValue fields of the updates, followed by the duplicates fields. If all fields are equal, returns false.
func UpdateSetEqual ¶
UpdateSetEqual compares the contents of a and b and returns true if they are equal. Order of the slices is ignored.
Types ¶
type Binary ¶ added in v0.8.8
type Binary []byte
Binary is a type that is used for fields that have a YANG type of binary. It is used such that binary fields can be distinguished from leaf-lists of uint8s (which are mapped to []uint8, equivalent to []byte in reflection).
func (Binary) IsExampleUnion ¶ added in v0.8.8
func (Binary) IsExampleUnion()
func (Binary) IsTestUnion ¶ added in v0.8.8
func (Binary) IsTestUnion()
func (Binary) IsTestUnion2 ¶ added in v0.8.8
func (Binary) IsTestUnion2()
func (Binary) Is_UnionLeafTypeSimple ¶ added in v0.8.8
func (Binary) Is_UnionLeafTypeSimple()
type ComparerOpt ¶
type ComparerOpt interface {
IsComparerOpt()
}
ComparerOpt is an interface that all comparison options must implement.
type CustomComparer ¶
CustomComparer allows for a comparer for a particular type to be overloaded such that an external caller can inject a new way to compare a specific field of a gNMI message. It is a map, keyed by a reflect.Type of the message field, with a value of a cmp.Option produced by cmp.Comparer(). NOTE: Proto comparison is done through protocmp -- this means any custom comparison of a proto field can only be done by supplying a protocmp-created cmp.Option.
func (CustomComparer) IsComparerOpt ¶
func (CustomComparer) IsComparerOpt()
IsComparerOpt marks CustomComparer as a ComparerOpt.
type IgnoreTimestamp ¶
type IgnoreTimestamp struct{}
IgnoreTimestamp is a comparison option that ignores timestamp values in gNMI messages.
func (IgnoreTimestamp) IsComparerOpt ¶
func (IgnoreTimestamp) IsComparerOpt()
IsComparerOpt marks IgnoreTimestamp as a ComparerOpt.
type TestUnion ¶ added in v0.8.8
type TestUnion interface {
IsTestUnion()
}
TestUnion is an interface defined within *this* (testutil) package that is satisfied by a subset of the above union types to aid testing within other packages. Enumerations defined within other test packages can still satisfy this interface by defining an IsTestUnion() method.
type TestUnion2 ¶ added in v0.8.8
type TestUnion2 interface {
IsTestUnion2()
}
type UnionBool ¶ added in v0.8.8
type UnionBool bool
UnionBool is a bool type assignable to unions of which it is a subtype.
func (UnionBool) IsExampleUnion ¶ added in v0.8.8
func (UnionBool) IsExampleUnion()
func (UnionBool) IsTestUnion2 ¶ added in v0.8.8
func (UnionBool) IsTestUnion2()
type UnionFloat64 ¶ added in v0.8.8
type UnionFloat64 float64
UnionFloat64 is a float64 type assignable to unions of which it is a subtype.
func (UnionFloat64) IsExampleUnion ¶ added in v0.8.8
func (UnionFloat64) IsExampleUnion()
type UnionInt16 ¶ added in v0.8.8
type UnionInt16 int16
UnionInt16 is an int16 type assignable to unions of which it is a subtype.
func (UnionInt16) IsTestUnion ¶ added in v0.8.8
func (UnionInt16) IsTestUnion()
func (UnionInt16) IsTestUnion2 ¶ added in v0.8.8
func (UnionInt16) IsTestUnion2()
type UnionInt32 ¶ added in v0.8.8
type UnionInt32 int32
UnionInt32 is an int32 type assignable to unions of which it is a subtype.
type UnionInt64 ¶ added in v0.8.8
type UnionInt64 int64
UnionInt64 is an int64 type assignable to unions of which it is a subtype.
func (UnionInt64) IsExampleUnion ¶ added in v0.8.8
func (UnionInt64) IsExampleUnion()
func (UnionInt64) IsTestUnion ¶ added in v0.8.8
func (UnionInt64) IsTestUnion()
func (UnionInt64) IsTestUnion2 ¶ added in v0.8.8
func (UnionInt64) IsTestUnion2()
func (UnionInt64) IsUnion ¶ added in v0.8.8
func (UnionInt64) IsUnion()
type UnionInt8 ¶ added in v0.8.8
type UnionInt8 int8
UnionInt8 is an int8 type assignable to unions of which it is a subtype.
type UnionString ¶ added in v0.8.8
type UnionString string
UnionString is a string type assignable to unions of which it is a subtype.
func (UnionString) IsExampleUnion ¶ added in v0.8.8
func (UnionString) IsExampleUnion()
func (UnionString) IsTestUnion ¶ added in v0.8.8
func (UnionString) IsTestUnion()
func (UnionString) IsUnion ¶ added in v0.8.8
func (UnionString) IsUnion()
func (UnionString) Is_UnionLeafTypeSimple ¶ added in v0.8.8
func (UnionString) Is_UnionLeafTypeSimple()
type UnionUint16 ¶ added in v0.8.8
type UnionUint16 uint16
UnionUint16 is a uint16 type assignable to unions of which it is a subtype.
type UnionUint32 ¶ added in v0.8.8
type UnionUint32 uint32
UnionUint32 is a uint32 type assignable to unions of which it is a subtype.
func (UnionUint32) IsExampleUnion ¶ added in v0.29.18
func (UnionUint32) IsExampleUnion()
func (UnionUint32) Is_UnionLeafTypeSimple ¶ added in v0.8.8
func (UnionUint32) Is_UnionLeafTypeSimple()
type UnionUint64 ¶ added in v0.8.8
type UnionUint64 uint64
UnionUint64 is a uint64 type assignable to unions of which it is a subtype.
type UnionUint8 ¶ added in v0.8.8
type UnionUint8 uint8
UnionUint8 is a uint8 type assignable to unions of which it is a subtype.
type UnionUnsupported ¶ added in v0.8.8
type UnionUnsupported struct {
Value interface{}
}
UnionUnsupported is an interface{} wrapper type for unsupported types. It is assignable to unions of which it is a subtype.
func (*UnionUnsupported) IsExampleUnion ¶ added in v0.8.8
func (*UnionUnsupported) IsExampleUnion()
func (*UnionUnsupported) IsU ¶ added in v0.8.8
func (*UnionUnsupported) IsU()
type YANGEmpty ¶ added in v0.8.8
type YANGEmpty bool
YANGEmpty is a type that is used for fields that have a YANG type of empty. It is used such that empty fields can be distinguished from boolean fields in the generated code.
func (YANGEmpty) IsExampleUnion ¶ added in v0.8.8
func (YANGEmpty) IsExampleUnion()