Skip to content
Snippets Groups Projects
Commit bb6ca6e9 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-1102-ActionRequestGoType' into 'master'

Изменены типы `extension.ActionRequest/Response` структуры определены с использованием внутренних типов perxis.

See merge request perxis/perxis-go!112
parents c438913c 29e06702
No related branches found
No related tags found
No related merge requests found
...@@ -8,44 +8,41 @@ import ( ...@@ -8,44 +8,41 @@ import (
type ( type (
ActionKind = pb.Action_Kind ActionKind = pb.Action_Kind
ActionTarget = pb.Target
ActionView = pb.Action_View
ResponseState = pb.ActionResponse_State ResponseState = pb.ActionResponse_State
ResponseFormat = pb.ActionResponse_Format
ActionRequest = pb.ActionRequest ActionRequest struct {
ActionResponse = pb.ActionResponse Extension string
Action string
ActionTarget = pb.Target SpaceID string
EnvID string
CollectionID string
ItemID string
ItemIDs []string
Fields []string
Metadata map[string]string
Refs []*references.Reference
Params *references.Reference
}
//ActionRequest struct { ActionResponse struct {
// Extension string State ResponseState
// Action string Target ActionTarget
// SpaceID string Format ResponseFormat
// EnvID string Msg string
// CollectionID string Title string
// ItemID string Image string
// ItemIDs []string Error string
// Fields []string Next []*Action
// Metadata map[string]string Metadata map[string]string
// Refs []*references.Reference Refs []*references.Reference
// Params *references.Reference }
//}
//
//ActionResponse struct {
// State ResponseState
// Msg string
// Error string
// Next []*Action
// Metadata map[string]string
// Refs []*references.Reference
//}
) )
const ( const (
ResponseDone = pb.ActionResponse_DONE ActionKindDefault = pb.Action_DEFAULT
ResponseError = pb.ActionResponse_ERROR
ResponsePending = pb.ActionResponse_PENDING
ResponseInProgress = pb.ActionResponse_IN_PROGRESS
ResponseParametersRequired = pb.ActionResponse_PARAMETERS_REQUIRED
ActionKindSpace = pb.Action_SPACE ActionKindSpace = pb.Action_SPACE
ActionKindEnvironment = pb.Action_ENVIRONMENT ActionKindEnvironment = pb.Action_ENVIRONMENT
ActionKindCollection = pb.Action_COLLECTION ActionKindCollection = pb.Action_COLLECTION
...@@ -53,6 +50,43 @@ const ( ...@@ -53,6 +50,43 @@ const (
ActionKindItems = pb.Action_ITEMS ActionKindItems = pb.Action_ITEMS
ActionKindRevision = pb.Action_REVISION ActionKindRevision = pb.Action_REVISION
ActionKindCreate = pb.Action_CREATE ActionKindCreate = pb.Action_CREATE
ActionTargetDefault = pb.Target_DEFAULT
ActionTargetModal = pb.Target_MODAL
ActionTargetWide = pb.Target_WIDE
ActionTargetMain = pb.Target_MAIN
ActionTargetDrawer = pb.Target_DRAWER
ActionTargetNotification = pb.Target_NOTIFICATION
ActionTargetBlank = pb.Target_BLANK
ActionTargetNone = pb.Target_NONE
ActionViewDefault = pb.Action_DEFAULT_VIEW
ActionViewHidden = pb.Action_HIDDEN_VIEW
ActionViewMainMenu = pb.Action_MAIN_MENU_VIEW
ActionViewMainMenuBottom = pb.Action_MAIN_MENU_BOTTOM_VIEW
ResponseDone = pb.ActionResponse_DONE
ResponseError = pb.ActionResponse_ERROR
ResponsePending = pb.ActionResponse_PENDING
ResponseInProgress = pb.ActionResponse_IN_PROGRESS
ResponseParametersRequired = pb.ActionResponse_PARAMETERS_REQUIRED
ResponseFormatPlain = pb.ActionResponse_PLAIN
ResponseFormatHtml = pb.ActionResponse_HTML
ResponseFormatMarkdown = pb.ActionResponse_MARKDOWN
)
var (
ActionKindName = pb.Action_Kind_name
ActionKindValue = pb.Action_Kind_value
ActionTargetName = pb.Target_name
ActionTargetValue = pb.Target_value
ActionViewName = pb.Action_View_name
ActionViewValue = pb.Action_View_value
ResponseStateName = pb.ActionResponse_State_name
ResponseStateValue = pb.ActionResponse_State_value
ResponseFormatName = pb.ActionResponse_Format_name
ResponseFormatValue = pb.ActionResponse_Format_value
) )
type Action struct { type Action struct {
...@@ -90,82 +124,82 @@ func ActionFromMap(d map[string]interface{}) (*Action, error) { ...@@ -90,82 +124,82 @@ func ActionFromMap(d map[string]interface{}) (*Action, error) {
return &action, err return &action, err
} }
//func ActionRequestToPB(req *ActionRequest) *pb.ActionRequest { func ActionRequestToPB(req *ActionRequest) *pb.ActionRequest {
// if req == nil { if req == nil {
// return nil return nil
// } }
// return &pb.ActionRequest{ return &pb.ActionRequest{
// Extension: req.Extension, Extension: req.Extension,
// Action: req.Action, Action: req.Action,
// SpaceId: req.SpaceID, SpaceId: req.SpaceID,
// EnvId: req.EnvID, EnvId: req.EnvID,
// CollectionId: req.CollectionID, CollectionId: req.CollectionID,
// ItemId: req.ItemID, ItemId: req.ItemID,
// ItemIds: req.ItemIDs, ItemIds: req.ItemIDs,
// Fields: req.Fields, Fields: req.Fields,
// Metadata: req.Metadata, Metadata: req.Metadata,
// Refs: references.ReferenceListToPB(req.Refs), Refs: references.ReferenceListToPB(req.Refs),
// Params: references.ReferenceToPB(req.Params), Params: references.ReferenceToPB(req.Params),
// } }
//} }
//
//func ActionRequestFromPB(req *pb.ActionRequest) *ActionRequest { func ActionRequestFromPB(req *pb.ActionRequest) *ActionRequest {
// if req == nil { if req == nil {
// return nil return nil
// } }
// return &ActionRequest{ return &ActionRequest{
// Extension: req.Extension, Extension: req.Extension,
// Action: req.Action, Action: req.Action,
// SpaceID: req.SpaceId, SpaceID: req.SpaceId,
// EnvID: req.EnvId, EnvID: req.EnvId,
// CollectionID: req.CollectionId, CollectionID: req.CollectionId,
// ItemID: req.ItemId, ItemID: req.ItemId,
// ItemIDs: req.ItemIds, ItemIDs: req.ItemIds,
// Fields: req.Fields, Fields: req.Fields,
// Metadata: req.Metadata, Metadata: req.Metadata,
// Refs: references.ReferenceListFromPB(req.Refs), Refs: references.ReferenceListFromPB(req.Refs),
// Params: references.ReferenceFromPB(req.Params), Params: references.ReferenceFromPB(req.Params),
// } }
//} }
//func ActionResponseToPB(out *ActionResponse) *pb.ActionResponse { func ActionResponseToPB(out *ActionResponse) *pb.ActionResponse {
// if out == nil { if out == nil {
// return nil return nil
// } }
//
// var next []*pb.Action var next []*pb.Action
// for _, a := range out.Next { for _, a := range out.Next {
// next = append(next, ActionToPB(a)) next = append(next, ActionToPB(a))
// } }
//
// return &pb.ActionResponse{ return &pb.ActionResponse{
// State: out.State, State: out.State,
// Msg: out.Msg, Msg: out.Msg,
// Error: out.Error, Error: out.Error,
// Next: next, Next: next,
// Metadata: out.Metadata, Metadata: out.Metadata,
// Refs: references.ReferenceListToPB(out.Refs), Refs: references.ReferenceListToPB(out.Refs),
// } }
//} }
//
//func ActionResponseFromPB(out *pb.ActionResponse) *ActionResponse { func ActionResponseFromPB(out *pb.ActionResponse) *ActionResponse {
// if out == nil { if out == nil {
// return nil return nil
// } }
//
// var next []*Action var next []*Action
// for _, a := range out.Next { for _, a := range out.Next {
// next = append(next, ActionFromPB(a)) next = append(next, ActionFromPB(a))
// } }
//
// return &ActionResponse{ return &ActionResponse{
// State: out.State, State: out.State,
// Msg: out.Msg, Msg: out.Msg,
// Error: out.Error, Error: out.Error,
// Next: next, Next: next,
// Metadata: out.Metadata, Metadata: out.Metadata,
// Refs: references.ReferenceListFromPB(out.Refs), Refs: references.ReferenceListFromPB(out.Refs),
// } }
//} }
func ActionFromPB(a *pb.Action) *Action { func ActionFromPB(a *pb.Action) *Action {
if a == nil { if a == nil {
...@@ -185,8 +219,7 @@ func ActionFromPB(a *pb.Action) *Action { ...@@ -185,8 +219,7 @@ func ActionFromPB(a *pb.Action) *Action {
Classes: a.Classes, Classes: a.Classes,
Refs: references.ReferenceListFromPB(a.Refs), Refs: references.ReferenceListFromPB(a.Refs),
ParamsCollection: a.ParamsCollection, ParamsCollection: a.ParamsCollection,
Request: a.Request, Request: ActionRequestFromPB(a.Request),
//Request: ActionRequestFromPB(a.Request),
NavigationAction: a.NavigationAction, NavigationAction: a.NavigationAction,
NavigationRoute: a.NavigationRoute, NavigationRoute: a.NavigationRoute,
Autorun: a.Autorun, Autorun: a.Autorun,
...@@ -194,26 +227,24 @@ func ActionFromPB(a *pb.Action) *Action { ...@@ -194,26 +227,24 @@ func ActionFromPB(a *pb.Action) *Action {
} }
} }
// func ActionToPB(a *Action) *pb.Action {
//func ActionToPB(a *Action) *pb.Action { if a == nil {
// if a == nil { return nil
// return nil }
// } return &pb.Action{
// return &pb.Action{ Extension: a.Extension,
// Extension: a.Extension, Action: a.Action,
// Action: a.Action, Name: a.Name,
// Name: a.Name, Description: a.Description,
// Description: a.Description, Icon: a.Icon,
// Icon: a.Icon, Image: references.ReferenceToPB(a.Image),
// Image: references.ReferenceToPB(a.Image), Groups: a.Groups,
// Groups: a.Groups, Kind: a.Kind,
// Kind: a.Kind, Classes: a.Classes,
// Classes: a.Classes, Refs: references.ReferenceListToPB(a.Refs),
// Refs: references.ReferenceListToPB(a.Refs), ParamsCollection: a.ParamsCollection,
// ParamsCollection: a.ParamsCollection, Request: ActionRequestToPB(a.Request),
// Request: a.Request, NavigationAction: a.NavigationAction,
// //Request: ActionRequestToPB(a.Request), NavigationRoute: a.NavigationRoute,
// NavigationAction: a.NavigationAction, }
// NavigationRoute: a.NavigationRoute, }
// }
//}
...@@ -83,6 +83,6 @@ func (c *Client) Check(ctx context.Context, req *CheckRequest) error { ...@@ -83,6 +83,6 @@ func (c *Client) Check(ctx context.Context, req *CheckRequest) error {
} }
func (c Client) Action(ctx context.Context, in *ActionRequest) (*ActionResponse, error) { func (c Client) Action(ctx context.Context, in *ActionRequest) (*ActionResponse, error) {
out, err := c.client.Action(ctx, in) out, err := c.client.Action(ctx, ActionRequestToPB(in))
return out, err return ActionResponseFromPB(out), err
} }
...@@ -5,6 +5,7 @@ package mocks ...@@ -5,6 +5,7 @@ package mocks
import ( import (
context "context" context "context"
extension "git.perx.ru/perxis/perxis-go/pkg/extension"
extensions "git.perx.ru/perxis/perxis-go/proto/extensions" extensions "git.perx.ru/perxis/perxis-go/proto/extensions"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
...@@ -16,23 +17,23 @@ type Extension struct { ...@@ -16,23 +17,23 @@ type Extension struct {
} }
// Action provides a mock function with given fields: ctx, in // Action provides a mock function with given fields: ctx, in
func (_m *Extension) Action(ctx context.Context, in *extensions.ActionRequest) (*extensions.ActionResponse, error) { func (_m *Extension) Action(ctx context.Context, in *extension.ActionRequest) (*extension.ActionResponse, error) {
ret := _m.Called(ctx, in) ret := _m.Called(ctx, in)
var r0 *extensions.ActionResponse var r0 *extension.ActionResponse
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *extensions.ActionRequest) (*extensions.ActionResponse, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, *extension.ActionRequest) (*extension.ActionResponse, error)); ok {
return rf(ctx, in) return rf(ctx, in)
} }
if rf, ok := ret.Get(0).(func(context.Context, *extensions.ActionRequest) *extensions.ActionResponse); ok { if rf, ok := ret.Get(0).(func(context.Context, *extension.ActionRequest) *extension.ActionResponse); ok {
r0 = rf(ctx, in) r0 = rf(ctx, in)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*extensions.ActionResponse) r0 = ret.Get(0).(*extension.ActionResponse)
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, *extensions.ActionRequest) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *extension.ActionRequest) error); ok {
r1 = rf(ctx, in) r1 = rf(ctx, in)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
......
...@@ -17,23 +17,23 @@ type Manager struct { ...@@ -17,23 +17,23 @@ type Manager struct {
} }
// Action provides a mock function with given fields: ctx, in // Action provides a mock function with given fields: ctx, in
func (_m *Manager) Action(ctx context.Context, in *extensions.ActionRequest) (*extensions.ActionResponse, error) { func (_m *Manager) Action(ctx context.Context, in *extension.ActionRequest) (*extension.ActionResponse, error) {
ret := _m.Called(ctx, in) ret := _m.Called(ctx, in)
var r0 *extensions.ActionResponse var r0 *extension.ActionResponse
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *extensions.ActionRequest) (*extensions.ActionResponse, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, *extension.ActionRequest) (*extension.ActionResponse, error)); ok {
return rf(ctx, in) return rf(ctx, in)
} }
if rf, ok := ret.Get(0).(func(context.Context, *extensions.ActionRequest) *extensions.ActionResponse); ok { if rf, ok := ret.Get(0).(func(context.Context, *extension.ActionRequest) *extension.ActionResponse); ok {
r0 = rf(ctx, in) r0 = rf(ctx, in)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*extensions.ActionResponse) r0 = ret.Get(0).(*extension.ActionResponse)
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, *extensions.ActionRequest) error); ok { if rf, ok := ret.Get(1).(func(context.Context, *extension.ActionRequest) error); ok {
r1 = rf(ctx, in) r1 = rf(ctx, in)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/schema"
"git.perx.ru/perxis/perxis-go/pkg/schema/field" "git.perx.ru/perxis/perxis-go/pkg/schema/field"
"git.perx.ru/perxis/perxis-go/pkg/schema/validate" "git.perx.ru/perxis/perxis-go/pkg/schema/validate"
pb "git.perx.ru/perxis/perxis-go/proto/extensions"
) )
const ( const (
...@@ -30,7 +29,7 @@ func NewActionsCollection(spaceID, envID string) *collections.Collection { ...@@ -30,7 +29,7 @@ func NewActionsCollection(spaceID, envID string) *collections.Collection {
"image", references.Field([]string{"media"}).SetTitle("Изображение").WithUI(&field.UI{Widget: "Media"}), "image", references.Field([]string{"media"}).SetTitle("Изображение").WithUI(&field.UI{Widget: "Media"}),
"kind", field.Number( "kind", field.Number(
field.NumberFormatInt, field.NumberFormatInt,
validate.Enum(getEnumOpt(pb.Action_Kind_name)...), validate.Enum(getEnumOpt(ActionKindName)...),
).SetTitle("Вид").WithUI(&field.UI{Widget: "Select"}), ).SetTitle("Вид").WithUI(&field.UI{Widget: "Select"}),
"autorun", field.Bool().SetTitle("Автозапуск"). "autorun", field.Bool().SetTitle("Автозапуск").
SetDescription("Действие выполняется автоматически каждый раз при загрузке приложения"). SetDescription("Действие выполняется автоматически каждый раз при загрузке приложения").
...@@ -40,11 +39,11 @@ func NewActionsCollection(spaceID, envID string) *collections.Collection { ...@@ -40,11 +39,11 @@ func NewActionsCollection(spaceID, envID string) *collections.Collection {
WithUI(&field.UI{Widget: "Checkbox"}), WithUI(&field.UI{Widget: "Checkbox"}),
"target", field.Number( "target", field.Number(
field.NumberFormatInt, field.NumberFormatInt,
validate.Enum(getEnumOpt(pb.Target_name)...), validate.Enum(getEnumOpt(ActionTargetName)...),
).SetTitle("Отображение результата действия").WithUI(&field.UI{Widget: "Select"}), ).SetTitle("Отображение результата действия").WithUI(&field.UI{Widget: "Select"}),
"view", field.Number( "view", field.Number(
field.NumberFormatInt, field.NumberFormatInt,
validate.Enum(getEnumOpt(pb.Action_View_name)...), validate.Enum(getEnumOpt(ActionViewName)...),
).SetTitle("Отображение действия в интерфейсе").WithUI(&field.UI{Widget: "Select"}), ).SetTitle("Отображение действия в интерфейсе").WithUI(&field.UI{Widget: "Select"}),
"parent", field.String().SetTitle("Идентификатор родительского действия"), "parent", field.String().SetTitle("Идентификатор родительского действия"),
"order", field.Number(field.NumberFormatInt).SetTitle("Порядок отображения"). "order", field.Number(field.NumberFormatInt).SetTitle("Порядок отображения").
......
...@@ -47,6 +47,7 @@ func TestEqualSchema(t *testing.T) { ...@@ -47,6 +47,7 @@ func TestEqualSchema(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
s2 := schema.New() s2 := schema.New()
err = json.Unmarshal(b, s2) err = json.Unmarshal(b, s2)
require.NoError(t, err)
require.Equal(t, s1.Field, s2.Field) require.Equal(t, s1.Field, s2.Field)
} }
} }
...@@ -183,7 +183,7 @@ func (s *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.ActionRe ...@@ -183,7 +183,7 @@ func (s *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.ActionRe
return nil, err return nil, err
} }
out, err := svc[0].Action(ctx, in) out, err := svc[0].Action(ctx, ActionRequestFromPB(in))
if out == nil { if out == nil {
out = &ActionResponse{} out = &ActionResponse{}
...@@ -195,7 +195,7 @@ func (s *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.ActionRe ...@@ -195,7 +195,7 @@ func (s *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.ActionRe
out.Msg += errors.GetDetail(err) out.Msg += errors.GetDetail(err)
} }
return out, nil return ActionResponseToPB(out), nil
} }
func (s *Server) Start() error { func (s *Server) Start() error {
......
...@@ -55,8 +55,8 @@ func TestServer_Action(t *testing.T) { ...@@ -55,8 +55,8 @@ func TestServer_Action(t *testing.T) {
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
Action: "grpc:///test-extension/test-action", Action: "grpc:///test-extension/test-action",
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
}, },
want: &ActionResponse{State: ResponseDone}, want: &ActionResponse{State: ResponseDone},
}, },
...@@ -65,8 +65,8 @@ func TestServer_Action(t *testing.T) { ...@@ -65,8 +65,8 @@ func TestServer_Action(t *testing.T) {
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
Action: "some:///space/env/coll", Action: "some:///space/env/coll",
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
}, },
want: &ActionResponse{State: ResponseDone}, want: &ActionResponse{State: ResponseDone},
wantErr: "invalid action", wantErr: "invalid action",
...@@ -76,8 +76,8 @@ func TestServer_Action(t *testing.T) { ...@@ -76,8 +76,8 @@ func TestServer_Action(t *testing.T) {
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
Action: "test-action", Action: "test-action",
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
Extension: "test-extension", Extension: "test-extension",
}, },
want: &ActionResponse{State: ResponseDone}, want: &ActionResponse{State: ResponseDone},
...@@ -87,8 +87,8 @@ func TestServer_Action(t *testing.T) { ...@@ -87,8 +87,8 @@ func TestServer_Action(t *testing.T) {
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
Action: "grpc:///test-extension-2/test-action", Action: "grpc:///test-extension-2/test-action",
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
}, },
want: nil, want: nil,
wantErr: errors.Wrap(ErrUnknownExtension, "test-extension-2").Error(), wantErr: errors.Wrap(ErrUnknownExtension, "test-extension-2").Error(),
...@@ -98,8 +98,8 @@ func TestServer_Action(t *testing.T) { ...@@ -98,8 +98,8 @@ func TestServer_Action(t *testing.T) {
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
Action: "test-action", Action: "test-action",
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
}, },
want: nil, want: nil,
wantErr: "invalid action", wantErr: "invalid action",
...@@ -108,8 +108,8 @@ func TestServer_Action(t *testing.T) { ...@@ -108,8 +108,8 @@ func TestServer_Action(t *testing.T) {
name: "Deprecated call, without action and extension)", name: "Deprecated call, without action and extension)",
extension: getDummyExtension("test-extension"), extension: getDummyExtension("test-extension"),
in: &ActionRequest{ in: &ActionRequest{
SpaceId: "sp", SpaceID: "sp",
EnvId: "env", EnvID: "env",
}, },
want: nil, want: nil,
wantErr: "invalid action", wantErr: "invalid action",
...@@ -119,14 +119,14 @@ func TestServer_Action(t *testing.T) { ...@@ -119,14 +119,14 @@ func TestServer_Action(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
srv := NewServer(NamedExtensions(tt.extension)) srv := NewServer(NamedExtensions(tt.extension))
got, err := srv.Action(context.Background(), tt.in) got, err := srv.Action(context.Background(), ActionRequestToPB(tt.in))
if tt.wantErr != "" { if tt.wantErr != "" {
require.Error(t, err) require.Error(t, err)
assert.EqualErrorf(t, err, tt.wantErr, fmt.Sprintf("Action(%v)", tt.in)) assert.EqualErrorf(t, err, tt.wantErr, fmt.Sprintf("Action(%v)", tt.in))
return return
} }
require.NoError(t, err) require.NoError(t, err)
assert.Equalf(t, tt.want, got, "Action(%v)", tt.in) assert.Equalf(t, tt.want, ActionResponseFromPB(got), "Action(%v)", tt.in)
}) })
} }
} }
...@@ -20,7 +20,7 @@ func TestExtension_Action(t *testing.T) { ...@@ -20,7 +20,7 @@ func TestExtension_Action(t *testing.T) {
{ {
name: "Router with 1 named action", name: "Router with 1 named action",
desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"}, desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"},
in: &extension.ActionRequest{Action: "grpc:///test/action", SpaceId: "sp", EnvId: "env", CollectionId: "coll"}, in: &extension.ActionRequest{Action: "grpc:///test/action", SpaceID: "sp", EnvID: "env", CollectionID: "coll"},
want: "Called action", want: "Called action",
router: extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) { router: extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) {
return &extension.ActionResponse{State: extension.ResponseDone, Msg: "Called action"}, nil return &extension.ActionResponse{State: extension.ResponseDone, Msg: "Called action"}, nil
...@@ -30,7 +30,7 @@ func TestExtension_Action(t *testing.T) { ...@@ -30,7 +30,7 @@ func TestExtension_Action(t *testing.T) {
{ {
name: "Router with 2 named actions", name: "Router with 2 named actions",
desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"}, desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"},
in: &extension.ActionRequest{Action: "grpc:///test/action2", SpaceId: "sp", EnvId: "env", CollectionId: "coll"}, in: &extension.ActionRequest{Action: "grpc:///test/action2", SpaceID: "sp", EnvID: "env", CollectionID: "coll"},
want: "Called action2", want: "Called action2",
router: extension.Chain(extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) { router: extension.Chain(extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) {
return &extension.ActionResponse{State: extension.ResponseDone}, nil return &extension.ActionResponse{State: extension.ResponseDone}, nil
...@@ -42,7 +42,7 @@ func TestExtension_Action(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestExtension_Action(t *testing.T) {
{ {
name: "Error (no extension)", name: "Error (no extension)",
desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"}, desc: &extension.ExtensionDescriptor{Extension: "test", Title: "Test Extension", Description: "desc", Version: "v.0.0.1"},
in: &extension.ActionRequest{Action: "grpc:///test2/action2", SpaceId: "sp", EnvId: "env", CollectionId: "coll"}, in: &extension.ActionRequest{Action: "grpc:///test2/action2", SpaceID: "sp", EnvID: "env", CollectionID: "coll"},
router: extension.Chain(extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) { router: extension.Chain(extension.Named("action", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) {
return &extension.ActionResponse{State: extension.ResponseDone}, nil return &extension.ActionResponse{State: extension.ResponseDone}, nil
}), extension.Named("action2", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) { }), extension.Named("action2", func(ctx context.Context, url *extension.ActionURL, req *extension.ActionRequest) (*extension.ActionResponse, error) {
......
...@@ -2,7 +2,6 @@ package extension ...@@ -2,7 +2,6 @@ package extension
import ( import (
"context" "context"
"fmt"
"strings" "strings"
"git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/collections"
...@@ -78,15 +77,7 @@ func (s *storage) GetExtension(ctx context.Context, spaceID, envID string, exten ...@@ -78,15 +77,7 @@ func (s *storage) GetExtension(ctx context.Context, spaceID, envID string, exten
// FindExtensions возвращает состояния расширений в пространстве // FindExtensions возвращает состояния расширений в пространстве
func (s *storage) FindExtensions(ctx context.Context, spaceID, envID string, extensions ...string) ([]*Info, error) { func (s *storage) FindExtensions(ctx context.Context, spaceID, envID string, extensions ...string) ([]*Info, error) {
var itemsFilter *items.Filter itms, _, err := s.content.Items.Find(ctx, spaceID, envID, ExtensionsCollectionID, &items.Filter{ID: extensions})
if len(extensions) != 0 {
q := make([]interface{}, 0, len(extensions)+1)
for _, e := range extensions {
q = append(q, fmt.Sprintf("id contains '%s'", e))
}
}
itms, _, err := s.content.Items.Find(ctx, spaceID, envID, ExtensionsCollectionID, itemsFilter)
if err != nil && !strings.Contains(err.Error(), collections.ErrNotFound.Error()) { if err != nil && !strings.Contains(err.Error(), collections.ErrNotFound.Error()) {
return nil, err return nil, err
} }
......
...@@ -26,6 +26,9 @@ func (r *Reference) MarshalBSON() ([]byte, error) { ...@@ -26,6 +26,9 @@ func (r *Reference) MarshalBSON() ([]byte, error) {
} }
func ReferenceFromPB(refPB *pb.Reference) *Reference { func ReferenceFromPB(refPB *pb.Reference) *Reference {
if refPB == nil {
return nil
}
return &Reference{ return &Reference{
ID: refPB.Id, ID: refPB.Id,
CollectionID: refPB.CollectionId, CollectionID: refPB.CollectionId,
...@@ -45,6 +48,9 @@ func ReferenceFromItem(item *items.Item) *Reference { ...@@ -45,6 +48,9 @@ func ReferenceFromItem(item *items.Item) *Reference {
} }
func ReferenceToPB(ref *Reference) *pb.Reference { func ReferenceToPB(ref *Reference) *pb.Reference {
if ref == nil {
return nil
}
return &pb.Reference{ return &pb.Reference{
Id: ref.ID, Id: ref.ID,
CollectionId: ref.CollectionID, CollectionId: ref.CollectionID,
...@@ -52,14 +58,30 @@ func ReferenceToPB(ref *Reference) *pb.Reference { ...@@ -52,14 +58,30 @@ func ReferenceToPB(ref *Reference) *pb.Reference {
} }
} }
func ReferenceListFromPB(listPB []*pb.Reference) []*Reference { func ReferenceListFromPB(refsPB []*pb.Reference) []*Reference {
list := make([]*Reference, 0, len(listPB)) if refsPB == nil {
for _, refPB := range listPB { return nil
}
list := make([]*Reference, 0, len(refsPB))
for _, refPB := range refsPB {
list = append(list, ReferenceFromPB(refPB)) list = append(list, ReferenceFromPB(refPB))
} }
return list return list
} }
func ReferenceListToPB(refs []*Reference) []*pb.Reference {
if refs == nil {
return nil
}
list := make([]*pb.Reference, 0, len(refs))
for _, ref := range refs {
list = append(list, ReferenceToPB(ref))
}
return list
}
func (r *Reference) String() string { func (r *Reference) String() string {
if r == nil { if r == nil {
return "" return ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment