Skip to content
Snippets Groups Projects
Commit bec78dfb authored by Alena Petraki's avatar Alena Petraki
Browse files

Установка и регистрация сервера операция при создании сервера расширений

parent f34a1131
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,9 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/action"
"git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/operation"
commonpb "git.perx.ru/perxis/perxis-go/proto/common"
pb "git.perx.ru/perxis/perxis-go/proto/extensions"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
......@@ -21,8 +23,7 @@ func DefaultWrapErrFn() WrapErrFn {
type ServerOption func(c *Server)
// WrapErrs Оборачивать ошибки, возвращаемые от каждого из
// расширений, в название расширения
// WrapErrs Оборачивать ошибки, возвращаемые от каждого из расширений, в название расширения
func WrapErrs() ServerOption {
return func(c *Server) {
c.wrapErr = func(extension Extension, err error) error {
......@@ -80,10 +81,9 @@ type Server struct {
pb.UnimplementedExtensionServiceServer
}
func NewServer(operation operation.Service, options ...ServerOption) *Server {
func NewServer(options ...ServerOption) *Server {
srv := &Server{
// todo: нужно как-то неявно создавать и регистрировать сервер операций - ?
operations: operation,
operations: operation.NewDefaultService(),
wrapErr: DefaultWrapErrFn(),
}
......@@ -94,6 +94,11 @@ func NewServer(operation operation.Service, options ...ServerOption) *Server {
return srv
}
func RegisterServer(grpcSrv *grpc.Server, srv *Server) {
commonpb.RegisterOperationServiceServer(grpcSrv, operation.NewServer(srv.operations))
pb.RegisterExtensionServiceServer(grpcSrv, srv)
}
func (s *Server) Install(ctx context.Context, req *InstallRequest) (*operation.Proto, error) {
exts, err := s.extensions(ctx, req.Extensions...)
if err != nil {
......
......@@ -7,7 +7,6 @@ import (
"testing"
"git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/operation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
......@@ -119,7 +118,7 @@ func TestServer_Action(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
srv := NewServer(operation.NewDefaultService(), NamedExtensions(tt.extension))
srv := NewServer(NamedExtensions(tt.extension))
got, err := srv.Action(context.Background(), tt.in)
if tt.wantErr != "" {
require.Error(t, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment