Skip to content

Commit

Permalink
Remove unnecessary import path on pkg test (#1712)
Browse files Browse the repository at this point in the history
* fix insert test import path

Signed-off-by: kevindiu <[email protected]>

* update response validation logic

Signed-off-by: kevindiu <[email protected]>
  • Loading branch information
kevindiu authored Jun 27, 2022
1 parent 13c0e71 commit 75e578f
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions pkg/agent/core/ngt/handler/grpc/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,8 @@ import (
"github.com/vdaas/vald/internal/test/goleak"
"github.com/vdaas/vald/internal/test/mock"
"github.com/vdaas/vald/pkg/agent/core/ngt/service"

grpcStatus "google.golang.org/genproto/googleapis/rpc/status"
)

var objectStreamLocationComparators = []comparator.Option{
comparator.IgnoreUnexported(payload.Object_StreamLocation{}),
comparator.IgnoreUnexported(payload.Object_Location{}),
comparator.Comparer(func(x, y grpcStatus.Status) bool {
// ignore checking the detail of status
return x.Code == y.Code
}),
}

func Test_server_Insert(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1480,14 +1469,24 @@ func Test_server_StreamInsert(t *testing.T) {
strictExistCheckCfg = &payload.Insert_Config{
SkipStrictExistCheck: false,
}

objectStreamLocationComparators = []comparator.Option{
comparator.IgnoreUnexported(payload.Object_StreamLocation{}),
comparator.IgnoreUnexported(payload.Object_Location{}),

// ignore checking status, will validate it on Test_server_StreamInsert defaultCheckFunc
comparator.IgnoreFields(payload.Object_StreamLocation_Status{}, "Status"),
}

objectLocationComparators = []comparator.Option{
comparator.IgnoreUnexported(payload.Object_Location{}),
}
)

genObjectStreamLoc := func(code codes.Code) *payload.Object_StreamLocation {
return &payload.Object_StreamLocation{
Payload: &payload.Object_StreamLocation_Status{
Status: &grpcStatus.Status{
Code: int32(code),
},
Status: status.New(code, "").Proto(),
},
}
}
Expand Down Expand Up @@ -1521,7 +1520,21 @@ func Test_server_StreamInsert(t *testing.T) {
sortObjectStreamLocation(w.rpcResp)

if diff := comparator.Diff(rpcResp, w.rpcResp, objectStreamLocationComparators...); diff != "" {
return errors.Errorf(diff)
return errors.New(diff)
}

// check status
if len(rpcResp) != len(w.rpcResp) {
return errors.Errorf("gotResp length not match with wantResp, got: %#v, want: %#v", rpcResp, w.rpcResp)
}
for i, gotResp := range rpcResp {
wantResp := w.rpcResp[i]
if diff := comparator.Diff(gotResp.GetStatus().GetCode(), wantResp.GetStatus().GetCode()); diff != "" {
return errors.New(diff)
}
if diff := comparator.Diff(gotResp.GetLocation(), wantResp.GetLocation(), objectLocationComparators...); diff != "" {
return errors.New(diff)
}
}
return nil
}
Expand Down

0 comments on commit 75e578f

Please sign in to comment.