Skip to content

Commit 2becd6d

Browse files
authored
Support marshalling YANG empty values for TogNMINotifications. (#836)
* Support marshalling YANG empty values for TogNMINotifications. * Add a couple more tests to clarify behaviour when empty is part of a union type * Fix and remove .swp file
1 parent b000dd8 commit 2becd6d

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

testutil/.testutil.go.swp

-32 KB
Binary file not shown.

ygot/render.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ func findUpdatedLeaves(leaves any, s GoStruct, parent *gnmiPath) error {
568568
addLeaf(&path{p}, fval.Interface())
569569
}
570570
continue
571+
case reflect.Bool:
572+
if fval.Type().Name() == EmptyTypeName {
573+
// This is an empty value.
574+
// Only marshal if the empty leaf is present.
575+
if val := fval.Bool(); val {
576+
for _, p := range mapPaths {
577+
addLeaf(&path{p}, fval.Interface())
578+
}
579+
}
580+
}
571581
}
572582
}
573583
return errs.Err()

ygot/render_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,17 @@ func TestTogNMINotifications(t *testing.T) {
10541054
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_DoubleVal{42.0}},
10551055
}},
10561056
}},
1057+
}, {
1058+
name: "simple empty value leaf example",
1059+
inTimestamp: 42,
1060+
inStruct: &renderExample{Empty: true},
1061+
want: []*gnmipb.Notification{{
1062+
Timestamp: 42,
1063+
Update: []*gnmipb.Update{{
1064+
Path: &gnmipb.Path{Element: []string{"empty"}},
1065+
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_BoolVal{true}},
1066+
}},
1067+
}},
10571068
}, {
10581069
name: "struct with invalid GoStruct map",
10591070
inTimestamp: 42,
@@ -1174,6 +1185,17 @@ func TestTogNMINotifications(t *testing.T) {
11741185
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_BytesVal{[]byte(base64testString)}},
11751186
}},
11761187
}},
1188+
}, {
1189+
name: "struct with empty union",
1190+
inTimestamp: 42,
1191+
inStruct: &renderExample{UnionValSimple: testutil.YANGEmpty(false)},
1192+
want: []*gnmipb.Notification{{
1193+
Timestamp: 42,
1194+
Update: []*gnmipb.Update{{
1195+
Path: &gnmipb.Path{Element: []string{"union-val-simple"}},
1196+
Val: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_BoolVal{false}},
1197+
}},
1198+
}},
11771199
}, {
11781200
name: "string with leaf-list of union",
11791201
inTimestamp: 42,
@@ -1183,6 +1205,8 @@ func TestTogNMINotifications(t *testing.T) {
11831205
EnumTestVALTWO,
11841206
testutil.UnionInt64(42),
11851207
testutil.UnionFloat64(3.14),
1208+
testutil.YANGEmpty(true),
1209+
testutil.YANGEmpty(false),
11861210
},
11871211
},
11881212
want: []*gnmipb.Notification{{
@@ -1200,6 +1224,10 @@ func TestTogNMINotifications(t *testing.T) {
12001224
Value: &gnmipb.TypedValue_IntVal{42},
12011225
}, {
12021226
Value: &gnmipb.TypedValue_DoubleVal{3.14},
1227+
}, {
1228+
Value: &gnmipb.TypedValue_BoolVal{true},
1229+
}, {
1230+
Value: &gnmipb.TypedValue_BoolVal{false},
12031231
}},
12041232
},
12051233
},

0 commit comments

Comments
 (0)