Skip to content

Commit

Permalink
Fix unmarshaling in WatchAll
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Dec 6, 2022
1 parent a492dda commit cf06c1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ygnmi/ygnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func WatchAll[T any](ctx context.Context, c *Client, q WildcardQuery[T], pred fu
if _, ok := structs[pre]; !ok {
structs[pre] = q.goStruct()
}
val, err := unmarshalAndExtract[T](data, q, structs[pre])
val, err := unmarshalAndExtract[T](datapointGroups[pre], q, structs[pre])
if err != nil {
w.errCh <- err
return
Expand Down
15 changes: 13 additions & 2 deletions ygnmi/ygnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,9 @@ func TestWatchAll(t *testing.T) {
Update: []*gpb.Update{{
Path: key10Path,
Val: &gpb.TypedValue{Value: &gpb.TypedValue_IntVal{IntVal: 100}},
}, {
Path: testutil.GNMIPath(t, "model/a/single-key[key=11]/state/key"),
Val: &gpb.TypedValue{Value: &gpb.TypedValue_StringVal{StringVal: "test"}},
}},
}).Sync().Notification(&gpb.Notification{
Timestamp: startTime.Add(time.Millisecond).UnixNano(),
Expand All @@ -1963,18 +1966,26 @@ func TestWatchAll(t *testing.T) {
}).SetVal(&exampleoc.Model_SingleKey{
Value: ygot.Int64(100),
}),
(&ygnmi.Value[*exampleoc.Model_SingleKey]{
Timestamp: startTime,
Path: nonLeafKey11Path,
}).SetVal(&exampleoc.Model_SingleKey{
Key: ygot.String("test"),
}),
(&ygnmi.Value[*exampleoc.Model_SingleKey]{
Timestamp: startTime.Add(time.Millisecond),
Path: nonLeafKey11Path,
}).SetVal(&exampleoc.Model_SingleKey{
Value: ygot.Int64(101),
Key: ygot.String("test"),
}),
},
wantLastVal: (&ygnmi.Value[*exampleoc.Model_SingleKey]{
Timestamp: startTime.Add(time.Millisecond),
Path: nonLeafKey11Path,
}).SetVal(&exampleoc.Model_SingleKey{
Value: ygot.Int64(101),
Key: ygot.String("test"),
}),
}}
for _, tt := range nonLeafTests {
Expand All @@ -1993,8 +2004,8 @@ func TestWatchAll(t *testing.T) {
t.Errorf("Predicate(%d) got unexpected input (-want,+got):\n %s\nComplianceErrors:\n%v", i, diff, v.ComplianceErrors)
}
val, present := v.Val()
key10Cond = key10Cond || (present && proto.Equal(v.Path, nonLeafKey10Path) && *val.Value == 100)
key11Cond = key11Cond || (present && proto.Equal(v.Path, nonLeafKey11Path) && *val.Value == 101)
key10Cond = key10Cond || (present && proto.Equal(v.Path, nonLeafKey10Path) && val.Value != nil && *val.Value == 100)
key11Cond = key11Cond || (present && proto.Equal(v.Path, nonLeafKey11Path) && val.Value != nil && *val.Value == 101)
i++
if key10Cond && key11Cond {
return nil
Expand Down

0 comments on commit cf06c1a

Please sign in to comment.