Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ mock:
-destination=internal/app/auth/mock/auth.go \
github.com/ozontech/seq-ui/internal/app/auth \
OIDCProvider,JWTProvider
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/dashboards/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/dashboards \
Service

.PHONY: protoc
protoc:
Expand Down
6 changes: 3 additions & 3 deletions internal/api/dashboards/v1/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package grpc

import (
"github.com/ozontech/seq-ui/internal/api/profiles"
"github.com/ozontech/seq-ui/internal/pkg/service"
dashboardsservice "github.com/ozontech/seq-ui/internal/pkg/service/dashboards"
"github.com/ozontech/seq-ui/pkg/dashboards/v1"
)

type API struct {
dashboards.UnimplementedDashboardsServiceServer

service service.Service
service dashboardsservice.Service
profiles *profiles.Profiles
}

func New(svc service.Service, p *profiles.Profiles) *API {
func New(svc dashboardsservice.Service, p *profiles.Profiles) *API {
return &API{
service: svc,
profiles: p,
Expand Down
6 changes: 3 additions & 3 deletions internal/api/dashboards/v1/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/ozontech/seq-ui/internal/api/profiles"
"github.com/ozontech/seq-ui/internal/app/types"
"github.com/ozontech/seq-ui/internal/pkg/service"
dashboardsservice "github.com/ozontech/seq-ui/internal/pkg/service/dashboards"
)

type API struct {
service service.Service
service dashboardsservice.Service
profiles *profiles.Profiles
}

func New(svc service.Service, p *profiles.Profiles) *API {
func New(svc dashboardsservice.Service, p *profiles.Profiles) *API {
return &API{
service: svc,
profiles: p,
Expand Down
61 changes: 20 additions & 41 deletions internal/api/dashboards/v1/http/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -12,20 +10,25 @@
"go.uber.org/mock/gomock"

"github.com/ozontech/seq-ui/internal/api/httputil"
"github.com/ozontech/seq-ui/internal/api/profiles"
"github.com/ozontech/seq-ui/internal/app/types"
mock "github.com/ozontech/seq-ui/internal/pkg/service/dashboards/mock"
)

func setupAPI(t *testing.T) (*API, *mock.MockService) {
ctrl := gomock.NewController(t)
mockedSvc := mock.NewMockService(ctrl)
p := profiles.New(mockedSvc)

Check failure on line 21 in internal/api/dashboards/v1/http/create_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use mockedSvc (variable of type *mock_dashboards.MockService) as service.Service value in argument to profiles.New: *mock_dashboards.MockService does not implement service.Service (missing method DeleteFavoriteQuery)
return New(mockedSvc, p), mockedSvc
}

func TestServeCreate(t *testing.T) {
userName := "unnamed"
var profileID int64 = 1
dashboardUUID := "064dc707-02b8-7000-8201-02a7f396738a"
dashboardName := "my_dashboard"
dashboardMeta := "my_meta"

formatReqBody := func(name, meta string) string {
return fmt.Sprintf(`{"name":%q,"meta":%q}`, name, meta)
}

type mockArgs struct {
req types.CreateDashboardRequest
resp string
Expand All @@ -35,18 +38,16 @@
tests := []struct {
name string

reqBody string
wantRespBody string
wantStatus int
req createRequest
want createResponse
wantErr bool

mockArgs *mockArgs
noUser bool
}{
{
name: "success",
reqBody: formatReqBody(dashboardName, dashboardMeta),
wantRespBody: fmt.Sprintf(`{"uuid":%q}`, dashboardUUID),
wantStatus: http.StatusOK,
name: "ok",
req: createRequest{Name: dashboardName, Meta: dashboardMeta},
want: createResponse{UUID: dashboardUUID},
mockArgs: &mockArgs{
req: types.CreateDashboardRequest{
ProfileID: profileID,
Expand All @@ -57,54 +58,32 @@
},
},
{
name: "err_invalid_request",
reqBody: "invalid-request",
wantStatus: http.StatusBadRequest,
noUser: true,
},
{
name: "err_no_user",
reqBody: formatReqBody(dashboardName, dashboardMeta),
wantStatus: http.StatusUnauthorized,
noUser: true,
},
{
name: "err_svc_empty_name",
reqBody: formatReqBody("", dashboardMeta),
wantStatus: http.StatusBadRequest,
},
{
name: "err_svc_empty_meta",
reqBody: formatReqBody(dashboardName, ""),
wantStatus: http.StatusBadRequest,
},
{
name: "err_repo_random",
reqBody: formatReqBody(dashboardName, dashboardMeta),
wantStatus: http.StatusInternalServerError,
name: "err_svc",
req: createRequest{Name: dashboardName, Meta: dashboardMeta},
wantErr: true,
mockArgs: &mockArgs{
req: types.CreateDashboardRequest{
ProfileID: profileID,
Name: dashboardName,
Meta: dashboardMeta,
},
err: errors.New("random repo err"),
err: errSomethingWrong,
},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

api, mockedRepo := newTestData(t)
req := httptest.NewRequest(http.MethodPost, "/dashboards/v1/", strings.NewReader(tt.reqBody))

Check failure on line 80 in internal/api/dashboards/v1/http/create_test.go

View workflow job for this annotation

GitHub Actions / lint

tt.reqBody undefined (type struct{name string; req createRequest; want createResponse; wantErr bool; mockArgs *mockArgs} has no field or method reqBody)

if tt.mockArgs != nil {
mockedRepo.EXPECT().Create(gomock.Any(), tt.mockArgs.req).
Return(tt.mockArgs.resp, tt.mockArgs.err).Times(1)
}
if !tt.noUser {

Check failure on line 86 in internal/api/dashboards/v1/http/create_test.go

View workflow job for this annotation

GitHub Actions / lint

tt.noUser undefined (type struct{name string; req createRequest; want createResponse; wantErr bool; mockArgs *mockArgs} has no field or method noUser)
req = req.WithContext(context.WithValue(req.Context(), types.UserKey{}, userName))
api.profiles.SetID(userName, profileID)
}
Expand All @@ -112,8 +91,8 @@
httputil.DoTestHTTP(t, httputil.TestDataHTTP{
Req: req,
Handler: api.serveCreate,
WantRespBody: tt.wantRespBody,

Check failure on line 94 in internal/api/dashboards/v1/http/create_test.go

View workflow job for this annotation

GitHub Actions / lint

tt.wantRespBody undefined (type struct{name string; req createRequest; want createResponse; wantErr bool; mockArgs *mockArgs} has no field or method wantRespBody)
WantStatus: tt.wantStatus,

Check failure on line 95 in internal/api/dashboards/v1/http/create_test.go

View workflow job for this annotation

GitHub Actions / lint

tt.wantStatus undefined (type struct{name string; req createRequest; want createResponse; wantErr bool; mockArgs *mockArgs} has no field or method wantStatus) (typecheck)
})
})
}
Expand Down
5 changes: 5 additions & 0 deletions internal/api/dashboards/v1/http/test_data.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package http

import (
"errors"
"testing"

"github.com/ozontech/seq-ui/internal/api/dashboards/v1/test"
repo_mock "github.com/ozontech/seq-ui/internal/pkg/repository/mock"
)

var (
errSomethingWrong = errors.New("something happened wrong")
)

func newTestData(t *testing.T) (*API, *repo_mock.MockDashboards) {
mock, s, p := test.NewTestData(t)
return New(s, p), mock

Check failure on line 17 in internal/api/dashboards/v1/http/test_data.go

View workflow job for this annotation

GitHub Actions / lint

cannot use s (variable of interface type service.Service) as dashboards.Service value in argument to New: service.Service does not implement dashboards.Service (missing method CreateDashboard)

Check failure on line 17 in internal/api/dashboards/v1/http/test_data.go

View workflow job for this annotation

GitHub Actions / test (-race)

cannot use s (variable of interface type service.Service) as dashboards.Service value in argument to New: service.Service does not implement dashboards.Service (missing method CreateDashboard)

Check failure on line 17 in internal/api/dashboards/v1/http/test_data.go

View workflow job for this annotation

GitHub Actions / test

cannot use s (variable of interface type service.Service) as dashboards.Service value in argument to New: service.Service does not implement dashboards.Service (missing method CreateDashboard)
}
145 changes: 145 additions & 0 deletions internal/pkg/service/dashboards/mock/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading