From db9807134f5fc0d25017319da484506d195286ae Mon Sep 17 00:00:00 2001 From: Wen Bo Li <50884368+wenovus@users.noreply.github.com> Date: Tue, 24 Nov 2020 17:53:44 -0500 Subject: [PATCH] Ignore default data values in findSetLeaves (#476) * Ignore default data values in findSetLeaves --- ygot/diff.go | 3 ++- ygot/diff_test.go | 11 +++++++++++ ygot/render_test.go | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ygot/diff.go b/ygot/diff.go index 9ec324e7a..06b77441b 100644 --- a/ygot/diff.go +++ b/ygot/diff.go @@ -263,7 +263,8 @@ func findSetLeaves(s GoStruct, opts ...DiffOpt) (map[*pathSpec]interface{}, erro ni.Annotation = []interface{}{vp} - if util.IsNilOrInvalidValue(ni.FieldValue) || util.IsValueStructPtr(ni.FieldValue) || util.IsValueMap(ni.FieldValue) { + // Ignore non-data, or default data values. + if util.IsNilOrInvalidValue(ni.FieldValue) || util.IsValueNilOrDefault(ni.FieldValue.Interface()) || util.IsValueStructPtr(ni.FieldValue) || util.IsValueMap(ni.FieldValue) { return } diff --git a/ygot/diff_test.go b/ygot/diff_test.go index 328a9b606..a640eb807 100644 --- a/ygot/diff_test.go +++ b/ygot/diff_test.go @@ -151,6 +151,7 @@ type basicStruct struct { StringValue *string `path:"string-value"` StructValue *basicStructTwo `path:"struct-value"` MapValue map[string]*basicListMember `path:"map-list"` + EmptyValue YANGEmpty `path:"empty-value"` } func (*basicStruct) IsYANGGoStruct() {} @@ -429,6 +430,16 @@ func TestFindSetLeaves(t *testing.T) { desc: "struct with fields missing path annotation", inStruct: &errorStruct{Value: String("foo")}, wantErr: "error from ForEachDataField iteration: field Value did not specify a path", + }, { + desc: "struct with empty value", + inStruct: &basicStruct{EmptyValue: YANGEmpty(true)}, + want: map[*pathSpec]interface{}{ + { + gNMIPaths: []*gnmipb.Path{{ + Elem: []*gnmipb.PathElem{{Name: "empty-value"}}, + }}, + }: YANGEmpty(true), + }, }, { desc: "multi-level string values", inStruct: &basicStruct{ diff --git a/ygot/render_test.go b/ygot/render_test.go index 3e06ad7ff..53a3e1928 100644 --- a/ygot/render_test.go +++ b/ygot/render_test.go @@ -838,8 +838,9 @@ func (*renderExampleUnionEnum) IsRenderUnionExample() {} // renderExampleChild is a child of the renderExample struct. type renderExampleChild struct { - Val *uint64 `path:"val"` - Enum EnumTest `path:"enum"` + Val *uint64 `path:"val"` + Enum EnumTest `path:"enum"` + Empty YANGEmpty `path:"empty"` } // IsYANGGoStruct implements the GoStruct interface.