Skip to content
Snippets Groups Projects
Commit 47566e65 authored by ko_oler's avatar ko_oler
Browse files

правки по ПР: добавлена проверка на переданный extension ID, поправлены тесты

parent c9c1d1b5
No related branches found
No related tags found
No related merge requests found
...@@ -19,19 +19,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -19,19 +19,7 @@ func TestActionURL_New(t *testing.T) {
{ {
name: "Without action", name: "Without action",
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{},
Scheme: "",
Opaque: "",
User: nil,
Host: "",
Path: "",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
},
}, },
wantErr: assert.NoError, wantErr: assert.NoError,
}, },
...@@ -40,17 +28,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -40,17 +28,7 @@ func TestActionURL_New(t *testing.T) {
action: "build-site", action: "build-site",
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{
Scheme: "",
Opaque: "",
User: nil,
Host: "",
Path: "build-site", Path: "build-site",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
}, },
}, },
url: "build-site", url: "build-site",
...@@ -62,16 +40,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -62,16 +40,7 @@ func TestActionURL_New(t *testing.T) {
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{
Scheme: "grpc", Scheme: "grpc",
Opaque: "",
User: nil,
Host: "",
Path: "/perxisweb/build-site", Path: "/perxisweb/build-site",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
}, },
}, },
url: "grpc:///perxisweb/build-site", url: "grpc:///perxisweb/build-site",
...@@ -83,16 +52,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -83,16 +52,7 @@ func TestActionURL_New(t *testing.T) {
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{
Scheme: "ui", Scheme: "ui",
Opaque: "",
User: nil,
Host: "",
Path: "/space/env/coll", Path: "/space/env/coll",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
}, },
}, },
url: "ui:///space/env/coll", url: "ui:///space/env/coll",
...@@ -104,16 +64,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -104,16 +64,7 @@ func TestActionURL_New(t *testing.T) {
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{
Scheme: "https", Scheme: "https",
Opaque: "",
User: nil,
Host: "perx.ru", Host: "perx.ru",
Path: "",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
}, },
}, },
url: "https://perx.ru", url: "https://perx.ru",
...@@ -131,16 +82,7 @@ func TestActionURL_New(t *testing.T) { ...@@ -131,16 +82,7 @@ func TestActionURL_New(t *testing.T) {
want: &URL{ want: &URL{
URL: &url.URL{ URL: &url.URL{
Scheme: "grpc", Scheme: "grpc",
Opaque: "",
User: nil,
Host: "",
Path: "/perxisweb", Path: "/perxisweb",
RawPath: "",
OmitHost: false,
ForceQuery: false,
RawQuery: "",
Fragment: "",
RawFragment: "",
}, },
}, },
wantErr: assert.NoError, wantErr: assert.NoError,
...@@ -166,33 +108,28 @@ func TestActionURL_String(t *testing.T) { ...@@ -166,33 +108,28 @@ func TestActionURL_String(t *testing.T) {
{ {
name: "GRPC action", name: "GRPC action",
url: "grpc:///perxisweb/build-site", url: "grpc:///perxisweb/build-site",
want: "grpc:///perxisweb/build-site",
}, },
{ {
name: "UI action #1", name: "UI action #1",
url: "ui:///space/env/coll", url: "ui:///space/env/coll",
want: "ui:///space/env/coll",
}, },
{ {
name: "UI action deprecated call #2", name: "UI action deprecated call #2",
url: "space/env/coll", url: "space/env/coll",
want: "space/env/coll",
}, },
{ {
name: "Https action", name: "Https action",
url: "https://perx.ru", url: "https://perx.ru",
want: "https://perx.ru",
}, },
{ {
name: "With action deprecated call", name: "With action deprecated call",
url: "extension-id", url: "extension-id",
want: "extension-id",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
p, _ := NewURL(tt.url) p, _ := NewURL(tt.url)
assert.Equalf(t, tt.want, p.String(), "String()") assert.Equalf(t, tt.url, p.String(), "String()")
}) })
} }
} }
...@@ -86,9 +86,12 @@ func (srv *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.Action ...@@ -86,9 +86,12 @@ func (srv *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.Action
return nil, err return nil, err
} }
ext := actionURL.Extension() ext := actionURL.Extension()
if ext == "" && in.Extension != "" { if ext == "" {
ext = in.Extension ext = in.Extension
} }
if ext == "" {
return nil, errors.New("extension ID required")
}
svc, ok := srv.services[ext] svc, ok := srv.services[ext]
if !ok { if !ok {
......
...@@ -168,6 +168,16 @@ func TestServer_Action(t *testing.T) { ...@@ -168,6 +168,16 @@ func TestServer_Action(t *testing.T) {
want: nil, want: nil,
wantErr: assert.Error, wantErr: assert.Error,
}, },
{
name: "Error (deprecated call, no action and extension)",
services: map[string]Extension{"test-extension": getDummyExtension("test-extension")},
in: &ActionRequest{
SpaceId: "sp",
EnvId: "env",
},
want: nil,
wantErr: assert.Error,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
......
...@@ -161,9 +161,12 @@ func (s *Extension) Action(ctx context.Context, in *extension.ActionRequest) (*e ...@@ -161,9 +161,12 @@ func (s *Extension) Action(ctx context.Context, in *extension.ActionRequest) (*e
return nil, err return nil, err
} }
ext := actionURL.Extension() ext := actionURL.Extension()
if ext == "" && in.Extension != "" { if ext == "" {
ext = in.Extension ext = in.Extension
} }
if ext == "" {
return nil, errors.New("extension ID required")
}
ok, err := extension.CheckInstalled(ctx, s.Content, in.SpaceId, in.EnvId, ext) 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