mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-25 17:42:25 +01:00
test: updated test cases
This commit is contained in:
@@ -3,13 +3,14 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
models2 "github.com/crawlab-team/crawlab/core/models/models/v2"
|
||||
"github.com/crawlab-team/crawlab/core/models/service"
|
||||
"github.com/crawlab-team/crawlab/db/mongo"
|
||||
"github.com/crawlab-team/crawlab/grpc"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -253,7 +254,11 @@ func (svr ModelBaseServiceServerV2) InsertMany(_ context.Context, req *grpc.Mode
|
||||
modelsSlice := reflect.ValueOf(modelsSlicePtr).Elem()
|
||||
modelsInterface := make([]any, modelsSlice.Len())
|
||||
for i := 0; i < modelsSlice.Len(); i++ {
|
||||
modelsInterface[i] = modelsSlice.Index(i).Interface()
|
||||
modelValue := modelsSlice.Index(i)
|
||||
if modelValue.FieldByName("Id").Interface().(primitive.ObjectID).IsZero() {
|
||||
modelValue.FieldByName("Id").Set(reflect.ValueOf(primitive.NewObjectID()))
|
||||
}
|
||||
modelsInterface[i] = modelValue.Interface()
|
||||
}
|
||||
modelSvc := GetModelService[bson.M](req.ModelType)
|
||||
r, err := modelSvc.GetCol().GetCollection().InsertMany(modelSvc.GetCol().GetContext(), modelsInterface)
|
||||
|
||||
@@ -39,7 +39,6 @@ type TaskServerV2 struct {
|
||||
func (svr TaskServerV2) Subscribe(stream grpc.TaskService_SubscribeServer) (err error) {
|
||||
for {
|
||||
msg, err := stream.Recv()
|
||||
utils.LogDebug(msg.String())
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,16 +38,3 @@ func HandleSuccessWithData(data interface{}) (res *grpc.Response, err error) {
|
||||
Data: bytes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func HandleSuccessWithListData(data interface{}, total int) (res *grpc.Response, err error) {
|
||||
bytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return HandleError(err)
|
||||
}
|
||||
return &grpc.Response{
|
||||
Code: grpc.ResponseCode_OK,
|
||||
Message: "success",
|
||||
Data: bytes,
|
||||
Total: int64(total),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user