Skip to content
Snippets Groups Projects
Commit 63c00a64 authored by ko_oler's avatar ko_oler
Browse files

правки по ПР

parent e848b956
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ import (
type ActionURL struct {
actionURL string
actionID string
extensionID string
extension string
scheme string
url *url.URL
}
......@@ -29,7 +29,7 @@ func (p *ActionURL) ID() string {
// Extension возвращает сохраненный в ActionURL id расширения
func (p *ActionURL) Extension() string {
return p.extensionID
return p.extension
}
// Scheme возвращает сохраненную в ActionURL схему
......@@ -59,7 +59,7 @@ func parseActionURL(action string) (*ActionURL, error) {
if len(splitPath) < 2 {
return nil, errors.Errorf("incorrect action URL, no action id: '%s'", action)
}
parsed.extensionID = splitPath[0]
parsed.extension = splitPath[0]
parsed.actionID = splitPath[1]
}
return parsed, nil
......
......@@ -9,30 +9,26 @@ import (
)
func TestNewActionURL(t *testing.T) {
u1, _ := url.Parse("build-site")
u2, _ := url.Parse("grpc:///perxisweb/build-site")
u3, _ := url.Parse("ui:///space/env/coll")
u4, _ := url.Parse("https://perx.ru")
tests := []struct {
name string
action string
want *ActionURL
url string
wantErr assert.ErrorAssertionFunc
}{
{
"Without action",
"",
&ActionURL{},
assert.NoError,
name: "Without action",
want: &ActionURL{},
wantErr: assert.NoError,
},
{
"Without deprecated action call",
"build-site",
&ActionURL{
name: "Without deprecated action call",
action: "build-site",
want: &ActionURL{
actionURL: "build-site",
url: u1,
},
assert.NoError,
url: "build-site",
wantErr: assert.NoError,
},
{
name: "With grpc action",
......@@ -40,10 +36,10 @@ func TestNewActionURL(t *testing.T) {
want: &ActionURL{
actionURL: "grpc:///perxisweb/build-site",
actionID: "build-site",
extensionID: "perxisweb",
extension: "perxisweb",
scheme: "grpc",
url: u2,
},
url: "grpc:///perxisweb/build-site",
wantErr: assert.NoError,
},
{
......@@ -52,10 +48,10 @@ func TestNewActionURL(t *testing.T) {
want: &ActionURL{
actionURL: "ui:///space/env/coll",
actionID: "",
extensionID: "",
extension: "",
scheme: "ui",
url: u3,
},
url: "ui:///space/env/coll",
wantErr: assert.NoError,
},
{
......@@ -64,8 +60,8 @@ func TestNewActionURL(t *testing.T) {
want: &ActionURL{
actionURL: "https://perx.ru",
scheme: "https",
url: u4,
},
url: "https://perx.ru",
wantErr: assert.NoError,
},
{
......@@ -77,6 +73,9 @@ func TestNewActionURL(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.url != "" {
tt.want.url, _ = url.Parse(tt.url)
}
got, err := NewActionURL(tt.action)
if !tt.wantErr(t, err, fmt.Sprintf("NewActionURL(%v)", tt.action)) {
return
......
......@@ -80,16 +80,16 @@ func (srv *Server) Update(ctx context.Context, request *UpdateRequest) (*UpdateR
}
func (srv *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.ActionResponse, error) {
extensionID := in.Extension
if extensionID == "" {
ext := in.Extension
if ext == "" {
actionURL, err := NewActionURL(in.Action)
if err != nil {
return nil, err
}
extensionID = actionURL.extensionID
ext = actionURL.extension
}
svc, ok := srv.services[extensionID]
svc, ok := srv.services[ext]
if !ok {
return nil, ErrUnknownExtension
}
......
......@@ -155,15 +155,15 @@ func (s *Extension) Uninstall(ctx context.Context, in *extension.UninstallReques
}
func (s *Extension) Action(ctx context.Context, in *extension.ActionRequest) (*extension.ActionResponse, error) {
extensionID := in.Extension
if extensionID == "" {
ext := in.Extension
if ext == "" {
actionURL, err := extension.NewActionURL(in.Action)
if err != nil {
return nil, err
}
extensionID = actionURL.Extension()
ext = actionURL.Extension()
}
ok, err := extension.CheckInstalled(ctx, s.Content, in.SpaceId, in.EnvId, extensionID)
ok, err := extension.CheckInstalled(ctx, s.Content, in.SpaceId, in.EnvId, ext)
if err != nil {
return nil, errors.Wrap(err, "check extension installed")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment