From 0259101ec270ae422dff0cf58c9be4193db102b5 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Wed, 22 Mar 2023 14:34:22 -0700 Subject: [PATCH] Fix origin handling for compare paths (#795) --- util/gnmi.go | 2 +- util/gnmi_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/util/gnmi.go b/util/gnmi.go index b422c9781..8274284d4 100644 --- a/util/gnmi.go +++ b/util/gnmi.go @@ -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 } diff --git a/util/gnmi_test.go b/util/gnmi_test.go index fbd832f25..0e08eba8f 100644 --- a/util/gnmi_test.go +++ b/util/gnmi_test.go @@ -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"),