Skip to content

Commit

Permalink
Fix origin handling for compare paths (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 authored Mar 22, 2023
1 parent dba644f commit 0259101
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const (
// ComparePaths returns the set relation between two paths.
// It returns an error if the paths are invalid or not one of the relations.
func ComparePaths(a, b *gpb.Path) CompareRelation {
if a.Origin != b.Origin {
if equivalentOrigin := a.Origin == b.Origin || (a.Origin == "" && b.Origin == "openconfig") || (a.Origin == "openconfig" && b.Origin == ""); !equivalentOrigin {
return Disjoint
}

Expand Down
10 changes: 10 additions & 0 deletions util/gnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,16 @@ func TestComparePaths(t *testing.T) {
a: mustStringToPath(t, "/foo[a=1][b=2]"),
b: mustStringToPath(t, "/foo[a=1][b=3]"),
want: util.Disjoint,
}, {
desc: "origin a openconfig and origin b blank",
a: &gpb.Path{Origin: "openconfig"},
b: &gpb.Path{Origin: ""},
want: util.Equal,
}, {
desc: "origin a blank and origin b openconfig",
a: &gpb.Path{Origin: ""},
b: &gpb.Path{Origin: "openconfig"},
want: util.Equal,
}, {
desc: "equal paths",
a: mustStringToPath(t, "/foo"),
Expand Down

0 comments on commit 0259101

Please sign in to comment.