diff --git a/authorizer/notebook.go b/authorizer/notebook.go index dacfe3e847..6dbbe06b8c 100644 --- a/authorizer/notebook.go +++ b/authorizer/notebook.go @@ -5,26 +5,25 @@ import ( "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/platform" - notebooks "github.com/influxdata/influxdb/v2/notebooks/service" ) -var _ notebooks.NotebookService = (*NotebookService)(nil) +var _ influxdb.NotebookService = (*NotebookService)(nil) -// NotebookService wraps a notebooks.NotebookService and authorizes actions +// NotebookService wraps an influxdb.NotebookService and authorizes actions // against it appropriately. type NotebookService struct { - s notebooks.NotebookService + s influxdb.NotebookService } // NewNotebookService constructs an instance of an authorizing check service. -func NewNotebookService(s notebooks.NotebookService) *NotebookService { +func NewNotebookService(s influxdb.NotebookService) *NotebookService { return &NotebookService{ s: s, } } // GetNotebook checks to see if the authorizer on context has read access to the id provided. -func (s *NotebookService) GetNotebook(ctx context.Context, id platform.ID) (*notebooks.Notebook, error) { +func (s *NotebookService) GetNotebook(ctx context.Context, id platform.ID) (*influxdb.Notebook, error) { nb, err := s.s.GetNotebook(ctx, id) if err != nil { return nil, err @@ -36,7 +35,7 @@ func (s *NotebookService) GetNotebook(ctx context.Context, id platform.ID) (*not } // CreateNotebook checks to see if the authorizer on context has write access for notebooks for organization id provided in the notebook body. -func (s *NotebookService) CreateNotebook(ctx context.Context, create *notebooks.NotebookReqBody) (*notebooks.Notebook, error) { +func (s *NotebookService) CreateNotebook(ctx context.Context, create *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { if _, _, err := AuthorizeCreate(ctx, influxdb.NotebooksResourceType, create.OrgID); err != nil { return nil, err } @@ -45,7 +44,7 @@ func (s *NotebookService) CreateNotebook(ctx context.Context, create *notebooks. } // UpdateNotebook checks to see if the authorizer on context has write access to the notebook provided. -func (s *NotebookService) UpdateNotebook(ctx context.Context, id platform.ID, update *notebooks.NotebookReqBody) (*notebooks.Notebook, error) { +func (s *NotebookService) UpdateNotebook(ctx context.Context, id platform.ID, update *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { nb, err := s.s.GetNotebook(ctx, id) if err != nil { return nil, err @@ -69,7 +68,7 @@ func (s *NotebookService) DeleteNotebook(ctx context.Context, id platform.ID) er } // ListNotebooks checks to see if the requesting user has read access to the provided org and returns a list of notebooks for that org if so. -func (s *NotebookService) ListNotebooks(ctx context.Context, filter notebooks.NotebookListFilter) ([]*notebooks.Notebook, error) { +func (s *NotebookService) ListNotebooks(ctx context.Context, filter influxdb.NotebookListFilter) ([]*influxdb.Notebook, error) { if _, _, err := AuthorizeOrgReadResource(ctx, influxdb.NotebooksResourceType, filter.OrgID); err != nil { return nil, err } diff --git a/authorizer/notebook_test.go b/authorizer/notebook_test.go index 62aa68132d..0ff97b76b0 100644 --- a/authorizer/notebook_test.go +++ b/authorizer/notebook_test.go @@ -12,8 +12,6 @@ import ( "github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2/mock" - notebookSvc "github.com/influxdata/influxdb/v2/notebooks/service" - notebookMocks "github.com/influxdata/influxdb/v2/notebooks/service/mocks" influxdbtesting "github.com/influxdata/influxdb/v2/testing" "github.com/stretchr/testify/require" ) @@ -31,7 +29,7 @@ func Test_GetNotebook(t *testing.T) { name string notebookOrg *platform.ID permissionOrg *platform.ID - wantRet *notebookSvc.Notebook + wantRet *influxdb.Notebook wantErr error }{ { @@ -56,7 +54,7 @@ func Test_GetNotebook(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrlr := gomock.NewController(t) - svc := notebookMocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) s := authorizer.NewNotebookService(svc) svc.EXPECT(). @@ -81,7 +79,7 @@ func Test_CreateNotebook(t *testing.T) { name string notebookOrg *platform.ID permissionOrg *platform.ID - wantRet *notebookSvc.Notebook + wantRet *influxdb.Notebook wantErr error }{ { @@ -106,7 +104,7 @@ func Test_CreateNotebook(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrlr := gomock.NewController(t) - svc := notebookMocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) s := authorizer.NewNotebookService(svc) perm := newTestPermission(influxdb.WriteAction, tt.permissionOrg) @@ -133,7 +131,7 @@ func Test_UpdateNotebook(t *testing.T) { name string notebookOrg *platform.ID permissionOrg *platform.ID - wantRet *notebookSvc.Notebook + wantRet *influxdb.Notebook wantErr error }{ { @@ -158,7 +156,7 @@ func Test_UpdateNotebook(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrlr := gomock.NewController(t) - svc := notebookMocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) s := authorizer.NewNotebookService(svc) svc.EXPECT(). @@ -211,7 +209,7 @@ func Test_DeleteNotebook(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrlr := gomock.NewController(t) - svc := notebookMocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) s := authorizer.NewNotebookService(svc) svc.EXPECT(). @@ -240,14 +238,14 @@ func Test_ListNotebooks(t *testing.T) { name string notebookOrg *platform.ID permissionOrg *platform.ID - wantRet []*notebookSvc.Notebook + wantRet []*influxdb.Notebook wantErr error }{ { "authorized to list notebooks for the specified org", orgID1, orgID1, - []*notebookSvc.Notebook{}, + []*influxdb.Notebook{}, nil, }, { @@ -265,11 +263,11 @@ func Test_ListNotebooks(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrlr := gomock.NewController(t) - svc := notebookMocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) s := authorizer.NewNotebookService(svc) perm := newTestPermission(influxdb.ReadAction, tt.permissionOrg) - filter := notebookSvc.NotebookListFilter{OrgID: *tt.notebookOrg} + filter := influxdb.NotebookListFilter{OrgID: *tt.notebookOrg} if tt.wantErr == nil { svc.EXPECT(). @@ -285,22 +283,22 @@ func Test_ListNotebooks(t *testing.T) { } } -func newTestNotebook(orgID platform.ID) *notebookSvc.Notebook { - return ¬ebookSvc.Notebook{ +func newTestNotebook(orgID platform.ID) *influxdb.Notebook { + return &influxdb.Notebook{ OrgID: orgID, ID: *nbID, Name: "test notebook", - Spec: notebookSvc.NotebookSpec{ + Spec: influxdb.NotebookSpec{ "hello": "goodbye", }, } } -func newTestReqBody(orgID platform.ID) *notebookSvc.NotebookReqBody { - return ¬ebookSvc.NotebookReqBody{ +func newTestReqBody(orgID platform.ID) *influxdb.NotebookReqBody { + return &influxdb.NotebookReqBody{ OrgID: orgID, Name: "testing", - Spec: notebookSvc.NotebookSpec{ + Spec: influxdb.NotebookSpec{ "hello": "goodbye", }, } diff --git a/cmd/influxd/launcher/launcher.go b/cmd/influxd/launcher/launcher.go index 1314803c8b..b7fcb956c6 100644 --- a/cmd/influxd/launcher/launcher.go +++ b/cmd/influxd/launcher/launcher.go @@ -43,7 +43,7 @@ import ( "github.com/influxdata/influxdb/v2/kv/migration/all" "github.com/influxdata/influxdb/v2/label" "github.com/influxdata/influxdb/v2/nats" - notebookSvc "github.com/influxdata/influxdb/v2/notebooks/service" + "github.com/influxdata/influxdb/v2/notebooks" notebookTransport "github.com/influxdata/influxdb/v2/notebooks/transport" endpointservice "github.com/influxdata/influxdb/v2/notification/endpoint/service" ruleservice "github.com/influxdata/influxdb/v2/notification/rule/service" @@ -940,7 +940,7 @@ func (m *Launcher) run(ctx context.Context, opts *InfluxdOpts) (err error) { ) } - notebookSvc, err := notebookSvc.NewService() + notebookSvc, err := notebooks.NewService() if err != nil { m.log.Error("Failed to initialize notebook service", zap.Error(err)) return err diff --git a/notebooks/service/mocks/service.go b/mock/notebook_service.go similarity index 56% rename from notebooks/service/mocks/service.go rename to mock/notebook_service.go index 35dc97fb93..63ac2f368d 100644 --- a/notebooks/service/mocks/service.go +++ b/mock/notebook_service.go @@ -1,16 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/influxdata/influxdb/v2/notebooks/service (interfaces: NotebookService) +// Source: notebook.go -// Package mocks is a generated GoMock package. -package mocks +// Package mock is a generated GoMock package. +package mock import ( context "context" reflect "reflect" gomock "github.com/golang/mock/gomock" + influxdb "github.com/influxdata/influxdb/v2" platform "github.com/influxdata/influxdb/v2/kit/platform" - service "github.com/influxdata/influxdb/v2/notebooks/service" ) // MockNotebookService is a mock of NotebookService interface. @@ -37,75 +37,75 @@ func (m *MockNotebookService) EXPECT() *MockNotebookServiceMockRecorder { } // CreateNotebook mocks base method. -func (m *MockNotebookService) CreateNotebook(arg0 context.Context, arg1 *service.NotebookReqBody) (*service.Notebook, error) { +func (m *MockNotebookService) CreateNotebook(ctx context.Context, create *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateNotebook", arg0, arg1) - ret0, _ := ret[0].(*service.Notebook) + ret := m.ctrl.Call(m, "CreateNotebook", ctx, create) + ret0, _ := ret[0].(*influxdb.Notebook) ret1, _ := ret[1].(error) return ret0, ret1 } // CreateNotebook indicates an expected call of CreateNotebook. -func (mr *MockNotebookServiceMockRecorder) CreateNotebook(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNotebookServiceMockRecorder) CreateNotebook(ctx, create interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateNotebook", reflect.TypeOf((*MockNotebookService)(nil).CreateNotebook), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateNotebook", reflect.TypeOf((*MockNotebookService)(nil).CreateNotebook), ctx, create) } // DeleteNotebook mocks base method. -func (m *MockNotebookService) DeleteNotebook(arg0 context.Context, arg1 platform.ID) error { +func (m *MockNotebookService) DeleteNotebook(ctx context.Context, id platform.ID) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteNotebook", arg0, arg1) + ret := m.ctrl.Call(m, "DeleteNotebook", ctx, id) ret0, _ := ret[0].(error) return ret0 } // DeleteNotebook indicates an expected call of DeleteNotebook. -func (mr *MockNotebookServiceMockRecorder) DeleteNotebook(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNotebookServiceMockRecorder) DeleteNotebook(ctx, id interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteNotebook", reflect.TypeOf((*MockNotebookService)(nil).DeleteNotebook), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteNotebook", reflect.TypeOf((*MockNotebookService)(nil).DeleteNotebook), ctx, id) } // GetNotebook mocks base method. -func (m *MockNotebookService) GetNotebook(arg0 context.Context, arg1 platform.ID) (*service.Notebook, error) { +func (m *MockNotebookService) GetNotebook(ctx context.Context, id platform.ID) (*influxdb.Notebook, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNotebook", arg0, arg1) - ret0, _ := ret[0].(*service.Notebook) + ret := m.ctrl.Call(m, "GetNotebook", ctx, id) + ret0, _ := ret[0].(*influxdb.Notebook) ret1, _ := ret[1].(error) return ret0, ret1 } // GetNotebook indicates an expected call of GetNotebook. -func (mr *MockNotebookServiceMockRecorder) GetNotebook(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNotebookServiceMockRecorder) GetNotebook(ctx, id interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNotebook", reflect.TypeOf((*MockNotebookService)(nil).GetNotebook), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNotebook", reflect.TypeOf((*MockNotebookService)(nil).GetNotebook), ctx, id) } // ListNotebooks mocks base method. -func (m *MockNotebookService) ListNotebooks(arg0 context.Context, arg1 service.NotebookListFilter) ([]*service.Notebook, error) { +func (m *MockNotebookService) ListNotebooks(ctx context.Context, filter influxdb.NotebookListFilter) ([]*influxdb.Notebook, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListNotebooks", arg0, arg1) - ret0, _ := ret[0].([]*service.Notebook) + ret := m.ctrl.Call(m, "ListNotebooks", ctx, filter) + ret0, _ := ret[0].([]*influxdb.Notebook) ret1, _ := ret[1].(error) return ret0, ret1 } // ListNotebooks indicates an expected call of ListNotebooks. -func (mr *MockNotebookServiceMockRecorder) ListNotebooks(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockNotebookServiceMockRecorder) ListNotebooks(ctx, filter interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListNotebooks", reflect.TypeOf((*MockNotebookService)(nil).ListNotebooks), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListNotebooks", reflect.TypeOf((*MockNotebookService)(nil).ListNotebooks), ctx, filter) } // UpdateNotebook mocks base method. -func (m *MockNotebookService) UpdateNotebook(arg0 context.Context, arg1 platform.ID, arg2 *service.NotebookReqBody) (*service.Notebook, error) { +func (m *MockNotebookService) UpdateNotebook(ctx context.Context, id platform.ID, update *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateNotebook", arg0, arg1, arg2) - ret0, _ := ret[0].(*service.Notebook) + ret := m.ctrl.Call(m, "UpdateNotebook", ctx, id, update) + ret0, _ := ret[0].(*influxdb.Notebook) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateNotebook indicates an expected call of UpdateNotebook. -func (mr *MockNotebookServiceMockRecorder) UpdateNotebook(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockNotebookServiceMockRecorder) UpdateNotebook(ctx, id, update interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNotebook", reflect.TypeOf((*MockNotebookService)(nil).UpdateNotebook), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNotebook", reflect.TypeOf((*MockNotebookService)(nil).UpdateNotebook), ctx, id, update) } diff --git a/notebooks/service/service.go b/notebook.go similarity index 72% rename from notebooks/service/service.go rename to notebook.go index 82385a6e73..cca11f1570 100644 --- a/notebooks/service/service.go +++ b/notebook.go @@ -1,12 +1,39 @@ -package service +package influxdb import ( "context" + "fmt" "time" "github.com/influxdata/influxdb/v2/kit/platform" + "github.com/influxdata/influxdb/v2/kit/platform/errors" ) +var ( + ErrOrgIDRequired = fieldRequiredError("OrgID") + ErrNameRequired = fieldRequiredError("Name") + ErrSpecRequired = fieldRequiredError("Spec") + ErrOffsetNegative = &errors.Error{ + Code: errors.EInvalid, + Msg: "offset cannot be negative", + } + ErrLimitLTEZero = &errors.Error{ + Code: errors.EInvalid, + Msg: "limit cannot be less-than or equal-to zero", + } + ErrNotebookNotFound = &errors.Error{ + Code: errors.ENotFound, + Msg: "notebook not found", + } +) + +func fieldRequiredError(field string) error { + return &errors.Error{ + Code: errors.EInvalid, + Msg: fmt.Sprintf("%s required", field), + } +} + // Notebook represents all visual and query data for a notebook. type Notebook struct { OrgID platform.ID `json:"orgID"` diff --git a/notebooks/service/service_test.go b/notebook_test.go similarity index 99% rename from notebooks/service/service_test.go rename to notebook_test.go index 8dd13b5183..6871e5562b 100644 --- a/notebooks/service/service_test.go +++ b/notebook_test.go @@ -1,4 +1,4 @@ -package service +package influxdb import ( "testing" diff --git a/notebooks/service/fake_store.go b/notebooks/fake_store.go similarity index 71% rename from notebooks/service/fake_store.go rename to notebooks/fake_store.go index ef92c0a17f..7ea023ccce 100644 --- a/notebooks/service/fake_store.go +++ b/notebooks/fake_store.go @@ -2,30 +2,31 @@ // For now it enables user experimentation with the UI in front of the notebooks // backend server. -package service +package notebooks import ( "context" "time" + "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/snowflake" ) -var _ NotebookService = (*FakeStore)(nil) +var _ influxdb.NotebookService = (*FakeStore)(nil) type FakeStore struct { - list map[string][]*Notebook + list map[string][]*influxdb.Notebook } func NewService() (*FakeStore, error) { return &FakeStore{ - list: make(map[string][]*Notebook), + list: make(map[string][]*influxdb.Notebook), }, nil } -func (s *FakeStore) GetNotebook(ctx context.Context, id platform.ID) (*Notebook, error) { - ns := []*Notebook{} +func (s *FakeStore) GetNotebook(ctx context.Context, id platform.ID) (*influxdb.Notebook, error) { + ns := []*influxdb.Notebook{} for _, nList := range s.list { ns = append(ns, nList...) @@ -37,22 +38,22 @@ func (s *FakeStore) GetNotebook(ctx context.Context, id platform.ID) (*Notebook, } } - return nil, ErrNotebookNotFound + return nil, influxdb.ErrNotebookNotFound } -func (s *FakeStore) ListNotebooks(ctx context.Context, filter NotebookListFilter) ([]*Notebook, error) { +func (s *FakeStore) ListNotebooks(ctx context.Context, filter influxdb.NotebookListFilter) ([]*influxdb.Notebook, error) { o := filter.OrgID ns, ok := s.list[o.String()] if !ok { - return []*Notebook{}, nil + return []*influxdb.Notebook{}, nil } return ns, nil } -func (s *FakeStore) CreateNotebook(ctx context.Context, create *NotebookReqBody) (*Notebook, error) { - n := &Notebook{ +func (s *FakeStore) CreateNotebook(ctx context.Context, create *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { + n := &influxdb.Notebook{ OrgID: create.OrgID, Name: create.Name, Spec: create.Spec, @@ -81,10 +82,10 @@ func (s *FakeStore) DeleteNotebook(ctx context.Context, id platform.ID) error { } if foundOrg == "" { - return ErrNotebookNotFound + return influxdb.ErrNotebookNotFound } - newNs := []*Notebook{} + newNs := []*influxdb.Notebook{} for _, b := range s.list[foundOrg] { if b.ID != id { @@ -96,7 +97,7 @@ func (s *FakeStore) DeleteNotebook(ctx context.Context, id platform.ID) error { return nil } -func (s *FakeStore) UpdateNotebook(ctx context.Context, id platform.ID, update *NotebookReqBody) (*Notebook, error) { +func (s *FakeStore) UpdateNotebook(ctx context.Context, id platform.ID, update *influxdb.NotebookReqBody) (*influxdb.Notebook, error) { n, err := s.GetNotebook(ctx, id) if err != nil { return nil, err diff --git a/notebooks/service/error.go b/notebooks/service/error.go deleted file mode 100644 index 60a20cdba4..0000000000 --- a/notebooks/service/error.go +++ /dev/null @@ -1,32 +0,0 @@ -package service - -import ( - "fmt" - - "github.com/influxdata/influxdb/v2/kit/platform/errors" -) - -var ( - ErrOrgIDRequired = fieldRequiredError("OrgID") - ErrNameRequired = fieldRequiredError("Name") - ErrSpecRequired = fieldRequiredError("Spec") - ErrOffsetNegative = &errors.Error{ - Code: errors.EInvalid, - Msg: "offset cannot be negative", - } - ErrLimitLTEZero = &errors.Error{ - Code: errors.EInvalid, - Msg: "limit cannot be less-than or equal-to zero", - } - ErrNotebookNotFound = &errors.Error{ - Code: errors.ENotFound, - Msg: "notebook not found", - } -) - -func fieldRequiredError(field string) error { - return &errors.Error{ - Code: errors.EInvalid, - Msg: fmt.Sprintf("%s required", field), - } -} diff --git a/notebooks/transport/http.go b/notebooks/transport/http.go index d0263c106a..e5f1db87d8 100644 --- a/notebooks/transport/http.go +++ b/notebooks/transport/http.go @@ -5,11 +5,11 @@ import ( "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" + "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/kit/platform/errors" kithttp "github.com/influxdata/influxdb/v2/kit/transport/http" - "github.com/influxdata/influxdb/v2/notebooks/service" "go.uber.org/zap" ) @@ -36,12 +36,12 @@ type NotebookHandler struct { log *zap.Logger api *kithttp.API - notebookService service.NotebookService + notebookService influxdb.NotebookService } func NewNotebookHandler( log *zap.Logger, - notebookService service.NotebookService, + notebookService influxdb.NotebookService, ) *NotebookHandler { h := &NotebookHandler{ log: log, @@ -101,7 +101,7 @@ func (h *NotebookHandler) handleGetNotebooks(w http.ResponseWriter, r *http.Requ return } - l, err := h.notebookService.ListNotebooks(ctx, service.NotebookListFilter{OrgID: *o}) + l, err := h.notebookService.ListNotebooks(ctx, influxdb.NotebookListFilter{OrgID: *o}) if err != nil { h.api.Err(w, r, err) return @@ -187,8 +187,8 @@ func (h *NotebookHandler) handleUpdateNotebook(w http.ResponseWriter, r *http.Re h.api.Respond(w, r, http.StatusOK, u) } -func (h *NotebookHandler) decodeNotebookReqBody(r *http.Request) (*service.NotebookReqBody, error) { - b := &service.NotebookReqBody{} +func (h *NotebookHandler) decodeNotebookReqBody(r *http.Request) (*influxdb.NotebookReqBody, error) { + b := &influxdb.NotebookReqBody{} if err := h.api.DecodeJSON(r.Body, b); err != nil { return nil, err } diff --git a/notebooks/transport/http_test.go b/notebooks/transport/http_test.go index 1bb7ace999..3a297eb784 100644 --- a/notebooks/transport/http_test.go +++ b/notebooks/transport/http_test.go @@ -8,10 +8,10 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/feature" "github.com/influxdata/influxdb/v2/kit/platform" - "github.com/influxdata/influxdb/v2/notebooks/service" - "github.com/influxdata/influxdb/v2/notebooks/service/mocks" + "github.com/influxdata/influxdb/v2/mock" "github.com/stretchr/testify/require" "go.uber.org/zap" "go.uber.org/zap/zaptest" @@ -22,18 +22,18 @@ var ( orgID, _ = platform.IDFromString(orgStr) idStr = "4321432143214321" id, _ = platform.IDFromString(idStr) - testNotebook = &service.Notebook{ + testNotebook = &influxdb.Notebook{ OrgID: *orgID, ID: *id, Name: "test notebook", - Spec: service.NotebookSpec{ + Spec: influxdb.NotebookSpec{ "hello": "goodbye", }, } - testReqBody = &service.NotebookReqBody{ + testReqBody = &influxdb.NotebookReqBody{ OrgID: *orgID, Name: "Test notebook", - Spec: service.NotebookSpec{ + Spec: influxdb.NotebookSpec{ "hello": "goodbye", }, } @@ -53,15 +53,15 @@ func TestNotebookHandler(t *testing.T) { req.URL.RawQuery = q.Encode() svc.EXPECT(). - ListNotebooks(gomock.Any(), service.NotebookListFilter{OrgID: *orgID}). - Return([]*service.Notebook{testNotebook}, nil) + ListNotebooks(gomock.Any(), influxdb.NotebookListFilter{OrgID: *orgID}). + Return([]*influxdb.Notebook{testNotebook}, nil) res := doTestRequest(t, req, http.StatusOK, true) - got := []*service.Notebook{} + got := []*influxdb.Notebook{} err := json.NewDecoder(res.Body).Decode(&got) require.NoError(t, err) - require.Equal(t, got, []*service.Notebook{testNotebook}) + require.Equal(t, got, []*influxdb.Notebook{testNotebook}) }) t.Run("create notebook happy path", func(t *testing.T) { @@ -76,7 +76,7 @@ func TestNotebookHandler(t *testing.T) { res := doTestRequest(t, req, http.StatusOK, true) - got := &service.Notebook{} + got := &influxdb.Notebook{} err := json.NewDecoder(res.Body).Decode(got) require.NoError(t, err) require.Equal(t, got, testNotebook) @@ -94,7 +94,7 @@ func TestNotebookHandler(t *testing.T) { res := doTestRequest(t, req, http.StatusOK, true) - got := &service.Notebook{} + got := &influxdb.Notebook{} err := json.NewDecoder(res.Body).Decode(got) require.NoError(t, err) require.Equal(t, got, testNotebook) @@ -125,7 +125,7 @@ func TestNotebookHandler(t *testing.T) { res := doTestRequest(t, req, http.StatusOK, true) - got := &service.Notebook{} + got := &influxdb.Notebook{} err := json.NewDecoder(res.Body).Decode(got) require.NoError(t, err) require.Equal(t, got, testNotebook) @@ -170,7 +170,7 @@ func TestNotebookHandler(t *testing.T) { }) t.Run("invalid request body returns 400", func(t *testing.T) { - badBady := &service.NotebookReqBody{ + badBady := &influxdb.NotebookReqBody{ OrgID: *orgID, } @@ -197,9 +197,9 @@ func TestNotebookHandler(t *testing.T) { // The svc generated is returned so that the caller can specify the expected // use of the mock service. -func newTestServer(t *testing.T) (*httptest.Server, *mocks.MockNotebookService) { +func newTestServer(t *testing.T) (*httptest.Server, *mock.MockNotebookService) { ctrlr := gomock.NewController(t) - svc := mocks.NewMockNotebookService(ctrlr) + svc := mock.NewMockNotebookService(ctrlr) // server needs to have a middleware to annotate the request context with the // appropriate feature flags while notebooks is still behind a feature flag server := annotatedTestServer(NewNotebookHandler(zaptest.NewLogger(t), svc))