Skip to content
Snippets Groups Projects
Commit fd8c1ba1 authored by Malte Bauch's avatar Malte Bauch
Browse files

Resolve "GetPath() test case for path `system` can fail if slice has the wrong order"

See merge request !269
parent 1a0059cb
Branches
Tags
2 merge requests!269Resolve "GetPath() test case for path `system` can fail if slice has the wrong order",!264WIP: Develop
Pipeline #98476 passed
This commit is part of merge request !264. Comments created here will be created in the context of that merge request.
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
"code.fbi.h-da.de/danet/yang-models/generated/openconfig" "code.fbi.h-da.de/danet/yang-models/generated/openconfig"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
...@@ -236,7 +237,16 @@ func Test_pnd_Get(t *testing.T) { ...@@ -236,7 +237,16 @@ func Test_pnd_Get(t *testing.T) {
func Test_pnd_GetPath(t *testing.T) { func Test_pnd_GetPath(t *testing.T) {
removeExistingStores() 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 { type args struct {
ctx context.Context ctx context.Context
request *ppb.GetPathRequest request *ppb.GetPathRequest
...@@ -252,7 +262,7 @@ func Test_pnd_GetPath(t *testing.T) { ...@@ -252,7 +262,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
request: &ppb.GetPathRequest{ request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250, Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(), Did: mockDevice.ID().String(),
Path: "system/config/hostname", Path: "system/config/hostname",
Pid: mockPnd.ID().String(), Pid: mockPnd.ID().String(),
...@@ -278,7 +288,7 @@ func Test_pnd_GetPath(t *testing.T) { ...@@ -278,7 +288,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
request: &ppb.GetPathRequest{ request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250, Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(), Did: mockDevice.ID().String(),
Path: "system", Path: "system",
Pid: mockPnd.ID().String(), Pid: mockPnd.ID().String(),
...@@ -312,7 +322,7 @@ func Test_pnd_GetPath(t *testing.T) { ...@@ -312,7 +322,7 @@ func Test_pnd_GetPath(t *testing.T) {
args: args{ args: args{
ctx: context.Background(), ctx: context.Background(),
request: &ppb.GetPathRequest{ request: &ppb.GetPathRequest{
Timestamp: 1648488947324854250, Timestamp: time.Now().UnixNano(),
Did: mockDevice.ID().String(), Did: mockDevice.ID().String(),
Path: "this/path/is/not/valid", Path: "this/path/is/not/valid",
Pid: mockPnd.ID().String(), Pid: mockPnd.ID().String(),
...@@ -335,16 +345,8 @@ func Test_pnd_GetPath(t *testing.T) { ...@@ -335,16 +345,8 @@ func Test_pnd_GetPath(t *testing.T) {
got := resp.GetDevice() 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 { 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) t.Errorf("GetPath() diff in the received notification %d: \n%s", i+1, diff)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment