Skip to content

Commit

Permalink
Ignore default data values in findSetLeaves (#476)
Browse files Browse the repository at this point in the history
* Ignore default data values in findSetLeaves
  • Loading branch information
wenovus authored Nov 24, 2020
1 parent b0419a6 commit db98071
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ygot/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions ygot/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions ygot/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit db98071

Please sign in to comment.