Skip to content
Snippets Groups Projects

WIP: Develop

Merged Ghost User requested to merge develop into master
1 file
+ 15
13
Compare changes
  • Side-by-side
  • Inline
@@ -19,6 +19,7 @@ import (
"code.fbi.h-da.de/danet/yang-models/generated/openconfig"
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid"
"github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
@@ -236,7 +237,16 @@ func Test_pnd_Get(t *testing.T) {
func Test_pnd_GetPath(t *testing.T) {
removeExistingStores()
// options to apply to cmp.Equal
opts := cmp.Options{
cmpopts.SortSlices(
func(x, y *gnmi.Update) bool {
return x.GetVal().String() < y.GetVal().String()
},
),
cmp.Comparer(proto.Equal),
}
type args struct {
ctx context.Context
request *ppb.GetPathRequest
@@ -252,7 +262,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{
ctx: context.Background(),
request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250,
Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(),
Path: "system/config/hostname",
Pid: mockPnd.ID().String(),
@@ -278,7 +288,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{
ctx: context.Background(),
request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250,
Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(),
Path: "system",
Pid: mockPnd.ID().String(),
@@ -312,7 +322,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{
ctx: context.Background(),
request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250,
Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(),
Path: "this/path/is/not/valid",
Pid: mockPnd.ID().String(),
@@ -335,16 +345,8 @@ func Test_pnd_GetPath(t *testing.T) {
got := resp.GetDevice()
// with the current implementation we should only get a
// notification set with length one. For the case that we do not
// get anything this makes sure we do not trigger a panic.
if len(got) >= 1 {
// set timestamp for equality; not the prettiest solution
tt.want[0].Timestamp = got[0].Timestamp
}
for i, n := range got {
if diff := cmp.Diff(n, tt.want[i], cmp.Comparer(proto.Equal)); diff != "" {
if diff := cmp.Diff(n.GetUpdate(), tt.want[i].GetUpdate(), opts...); diff != "" {
t.Errorf("GetPath() diff in the received notification %d: \n%s", i+1, diff)
}
}
Loading