Documentation ¶
Overview ¶
Package testutil contains a set of utilities that are useful within tests of ygot-related data.
Index ¶
- func GenerateUnifiedDiff(got, want string) (string, error)
- func GetResponseEqual(a, b *gnmipb.GetResponse, opts ...ComparerOpt) bool
- func JSONIETFComparer(a, b *gnmipb.TypedValue_JsonIetfVal) bool
- 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 ComparerOpt
- type CustomComparer
- type IgnoreTimestamp
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 ¶
func JSONIETFComparer(a, b *gnmipb.TypedValue_JsonIetfVal) bool
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 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 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().
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.