diff --git a/ygnmi/path_types.go b/ygnmi/path_types.go index 1401e27..8aad026 100644 --- a/ygnmi/path_types.go +++ b/ygnmi/path_types.go @@ -115,6 +115,19 @@ func ResolvePath(n PathStruct) (*gpb.Path, map[string]interface{}, error) { return &gpb.Path{Elem: p}, root.CustomData(), nil } +// MustPath calls ResolvePath and panics on error. +// It is intended for use in tests with generated PathStructs. +// +// ygnmi.MustResolvePath(ocpath.Interface("port0").Name().Config().PathStruct()) +// returns "/interfaces/interface[name=port0]/config/name +func MustPath(q UntypedQuery) *gpb.Path { + p, _, err := ResolvePath(q.PathStruct()) + if err != nil { + panic(err) + } + return p +} + // ResolveRelPath returns the partial []*gpb.PathElem representing the // PathStruct's relative path. func ResolveRelPath(n PathStruct) ([]*gpb.PathElem, []error) {