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