testutil

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil contains a set of utilities that are useful within tests of ygot-related data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUnifiedDiff

func GenerateUnifiedDiff(got, want string) (string, error)

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

func PathLess(a, b *gnmipb.Path) bool

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

func UpdateLess(a, b *gnmipb.Update) bool

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

func UpdateSetEqual(a, b []*gnmipb.Update) bool

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

type CustomComparer map[reflect.Type]cmp.Option

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.

Jump to

Keyboard shortcuts

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