pass user service to handler New function

pull/10616/head
zhulongcheng 2018-12-17 20:43:06 +08:00
parent 49d098346d
commit dcac51377e
14 changed files with 79 additions and 47 deletions

View File

@ -72,30 +72,26 @@ func NewAPIHandler(b *APIBackend) *APIHandler {
h.SessionHandler.SessionService = b.SessionService h.SessionHandler.SessionService = b.SessionService
h.SessionHandler.Logger = b.Logger.With(zap.String("handler", "basicAuth")) h.SessionHandler.Logger = b.Logger.With(zap.String("handler", "basicAuth"))
h.BucketHandler = NewBucketHandler(b.UserResourceMappingService, b.LabelService) h.BucketHandler = NewBucketHandler(b.UserResourceMappingService, b.LabelService, b.UserService)
h.BucketHandler.BucketService = b.BucketService h.BucketHandler.BucketService = b.BucketService
h.BucketHandler.BucketOperationLogService = b.BucketOperationLogService h.BucketHandler.BucketOperationLogService = b.BucketOperationLogService
h.BucketHandler.UserService = b.UserService
h.OrgHandler = NewOrgHandler(b.UserResourceMappingService, b.LabelService) h.OrgHandler = NewOrgHandler(b.UserResourceMappingService, b.LabelService, b.UserService)
h.OrgHandler.OrganizationService = b.OrganizationService h.OrgHandler.OrganizationService = b.OrganizationService
h.OrgHandler.BucketService = b.BucketService h.OrgHandler.BucketService = b.BucketService
h.OrgHandler.OrganizationOperationLogService = b.OrganizationOperationLogService h.OrgHandler.OrganizationOperationLogService = b.OrganizationOperationLogService
h.OrgHandler.UserService = b.UserService
h.UserHandler = NewUserHandler() h.UserHandler = NewUserHandler()
h.UserHandler.UserService = b.UserService h.UserHandler.UserService = b.UserService
h.UserHandler.BasicAuthService = b.BasicAuthService h.UserHandler.BasicAuthService = b.BasicAuthService
h.UserHandler.UserOperationLogService = b.UserOperationLogService h.UserHandler.UserOperationLogService = b.UserOperationLogService
h.DashboardHandler = NewDashboardHandler(b.UserResourceMappingService, b.LabelService) h.DashboardHandler = NewDashboardHandler(b.UserResourceMappingService, b.LabelService, b.UserService)
h.DashboardHandler.DashboardService = b.DashboardService h.DashboardHandler.DashboardService = b.DashboardService
h.DashboardHandler.DashboardOperationLogService = b.DashboardOperationLogService h.DashboardHandler.DashboardOperationLogService = b.DashboardOperationLogService
h.DashboardHandler.UserService = b.UserService
h.ViewHandler = NewViewHandler(b.UserResourceMappingService, b.LabelService) h.ViewHandler = NewViewHandler(b.UserResourceMappingService, b.LabelService, b.UserService)
h.ViewHandler.ViewService = b.ViewService h.ViewHandler.ViewService = b.ViewService
h.ViewHandler.UserService = b.UserService
h.MacroHandler = NewMacroHandler() h.MacroHandler = NewMacroHandler()
h.MacroHandler.MacroService = b.MacroService h.MacroHandler.MacroService = b.MacroService
@ -112,19 +108,18 @@ func NewAPIHandler(b *APIBackend) *APIHandler {
h.SetupHandler = NewSetupHandler() h.SetupHandler = NewSetupHandler()
h.SetupHandler.OnboardingService = b.OnboardingService h.SetupHandler.OnboardingService = b.OnboardingService
h.TaskHandler = NewTaskHandler(b.UserResourceMappingService, b.LabelService, b.Logger) h.TaskHandler = NewTaskHandler(b.UserResourceMappingService, b.LabelService, b.Logger, b.UserService)
h.TaskHandler.TaskService = b.TaskService h.TaskHandler.TaskService = b.TaskService
h.TaskHandler.AuthorizationService = b.AuthorizationService h.TaskHandler.AuthorizationService = b.AuthorizationService
h.TaskHandler.UserResourceMappingService = b.UserResourceMappingService h.TaskHandler.UserResourceMappingService = b.UserResourceMappingService
h.TaskHandler.UserService = b.UserService
h.TelegrafHandler = NewTelegrafHandler( h.TelegrafHandler = NewTelegrafHandler(
b.Logger.With(zap.String("handler", "telegraf")), b.Logger.With(zap.String("handler", "telegraf")),
b.UserResourceMappingService, b.UserResourceMappingService,
b.LabelService, b.LabelService,
b.TelegrafService, b.TelegrafService,
b.UserService,
) )
h.TelegrafHandler.UserService = b.UserService
h.WriteHandler = NewWriteHandler(b.PointsWriter) h.WriteHandler = NewWriteHandler(b.PointsWriter)
h.WriteHandler.OrganizationService = b.OrganizationService h.WriteHandler.OrganizationService = b.OrganizationService

View File

@ -39,11 +39,12 @@ const (
) )
// NewBucketHandler returns a new instance of BucketHandler. // NewBucketHandler returns a new instance of BucketHandler.
func NewBucketHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService) *BucketHandler { func NewBucketHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService, userService platform.UserService) *BucketHandler {
h := &BucketHandler{ h := &BucketHandler{
Router: NewRouter(), Router: NewRouter(),
UserResourceMappingService: mappingService, UserResourceMappingService: mappingService,
LabelService: labelService, LabelService: labelService,
UserService: userService,
} }
h.HandlerFunc("POST", bucketsPath, h.handlePostBucket) h.HandlerFunc("POST", bucketsPath, h.handlePostBucket)

View File

@ -124,7 +124,8 @@ func TestService_handleGetBuckets(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewBucketHandler(mappingService, labelService, userService)
h.BucketService = tt.fields.BucketService h.BucketService = tt.fields.BucketService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -242,7 +243,8 @@ func TestService_handleGetBucket(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewBucketHandler(mappingService, labelService, userService)
h.BucketService = tt.fields.BucketService h.BucketService = tt.fields.BucketService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -338,7 +340,8 @@ func TestService_handlePostBucket(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewBucketHandler(mappingService, labelService, userService)
h.BucketService = tt.fields.BucketService h.BucketService = tt.fields.BucketService
b, err := json.Marshal(newBucket(tt.args.bucket)) b, err := json.Marshal(newBucket(tt.args.bucket))
@ -433,7 +436,8 @@ func TestService_handleDeleteBucket(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewBucketHandler(mappingService, labelService, userService)
h.BucketService = tt.fields.BucketService h.BucketService = tt.fields.BucketService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -708,7 +712,8 @@ func TestService_handlePatchBucket(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewBucketHandler(mappingService, labelService, userService)
h.BucketService = tt.fields.BucketService h.BucketService = tt.fields.BucketService
upd := platform.BucketUpdate{} upd := platform.BucketUpdate{}
@ -776,7 +781,8 @@ func initBucketService(f platformtesting.BucketFields, t *testing.T) (platform.B
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
handler := NewBucketHandler(mappingService, labelService) userService := mock.NewUserService()
handler := NewBucketHandler(mappingService, labelService, userService)
handler.BucketService = svc handler.BucketService = svc
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
client := BucketService{ client := BucketService{

View File

@ -41,11 +41,12 @@ const (
) )
// NewDashboardHandler returns a new instance of DashboardHandler. // NewDashboardHandler returns a new instance of DashboardHandler.
func NewDashboardHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService) *DashboardHandler { func NewDashboardHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService, userService platform.UserService) *DashboardHandler {
h := &DashboardHandler{ h := &DashboardHandler{
Router: NewRouter(), Router: NewRouter(),
UserResourceMappingService: mappingService, UserResourceMappingService: mappingService,
LabelService: labelService, LabelService: labelService,
UserService: userService,
} }
h.HandlerFunc("POST", dashboardsPath, h.handlePostDashboard) h.HandlerFunc("POST", dashboardsPath, h.handlePostDashboard)

View File

@ -162,7 +162,8 @@ func TestService_handleGetDashboards(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -307,7 +308,8 @@ func TestService_handleGetDashboard(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -435,7 +437,8 @@ func TestService_handlePostDashboard(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
b, err := json.Marshal(tt.args.dashboard) b, err := json.Marshal(tt.args.dashboard)
@ -526,7 +529,8 @@ func TestService_handleDeleteDashboard(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -697,7 +701,8 @@ func TestService_handlePatchDashboard(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
upd := platform.DashboardUpdate{} upd := platform.DashboardUpdate{}
@ -807,7 +812,8 @@ func TestService_handlePostDashboardCell(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
b, err := json.Marshal(tt.args.cell) b, err := json.Marshal(tt.args.cell)
@ -891,7 +897,8 @@ func TestService_handleDeleteDashboardCell(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -1006,7 +1013,8 @@ func TestService_handlePatchDashboardCell(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
h := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
h := NewDashboardHandler(mappingService, labelService, userService)
h.DashboardService = tt.fields.DashboardService h.DashboardService = tt.fields.DashboardService
upd := platform.CellUpdate{} upd := platform.CellUpdate{}
@ -1105,9 +1113,10 @@ func initDashboardService(f platformtesting.DashboardFields, t *testing.T) (plat
mappingService := mock.NewUserResourceMappingService() mappingService := mock.NewUserResourceMappingService()
labelService := mock.NewLabelService() labelService := mock.NewLabelService()
handler := NewDashboardHandler(mappingService, labelService) userService := mock.NewUserService()
handler.DashboardService = svc h := NewDashboardHandler(mappingService, labelService, userService)
server := httptest.NewServer(handler) h.DashboardService = svc
server := httptest.NewServer(h)
client := DashboardService{ client := DashboardService{
Addr: server.URL, Addr: server.URL,
} }

View File

@ -44,11 +44,12 @@ const (
// NewOrgHandler returns a new instance of OrgHandler. // NewOrgHandler returns a new instance of OrgHandler.
func NewOrgHandler(mappingService platform.UserResourceMappingService, func NewOrgHandler(mappingService platform.UserResourceMappingService,
labelService platform.LabelService) *OrgHandler { labelService platform.LabelService, userService platform.UserService) *OrgHandler {
h := &OrgHandler{ h := &OrgHandler{
Router: NewRouter(), Router: NewRouter(),
UserResourceMappingService: mappingService, UserResourceMappingService: mappingService,
LabelService: labelService, LabelService: labelService,
UserService: userService,
} }
h.HandlerFunc("POST", organizationsPath, h.handlePostOrg) h.HandlerFunc("POST", organizationsPath, h.handlePostOrg)

View File

@ -28,7 +28,7 @@ func initOrganizationService(f platformtesting.OrganizationFields, t *testing.T)
} }
} }
handler := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) handler := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
handler.OrganizationService = svc handler.OrganizationService = svc
handler.BucketService = svc handler.BucketService = svc
server := httptest.NewServer(handler) server := httptest.NewServer(handler)
@ -123,7 +123,7 @@ func TestSecretService_handleGetSecrets(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) {
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.SecretService = tt.fields.SecretService h.SecretService = tt.fields.SecretService
u := fmt.Sprintf("http://any.url/api/v2/orgs/%s/secrets", tt.args.orgID) u := fmt.Sprintf("http://any.url/api/v2/orgs/%s/secrets", tt.args.orgID)
@ -193,7 +193,7 @@ func TestSecretService_handlePatchSecrets(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) {
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.SecretService = tt.fields.SecretService h.SecretService = tt.fields.SecretService
b, err := json.Marshal(tt.args.secrets) b, err := json.Marshal(tt.args.secrets)
@ -269,7 +269,7 @@ func TestSecretService_handleDeleteSecrets(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) {
h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewOrgHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.SecretService = tt.fields.SecretService h.SecretService = tt.fields.SecretService
b, err := json.Marshal(tt.args.secrets) b, err := json.Marshal(tt.args.secrets)

View File

@ -50,13 +50,14 @@ const (
) )
// NewTaskHandler returns a new instance of TaskHandler. // NewTaskHandler returns a new instance of TaskHandler.
func NewTaskHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService, logger *zap.Logger) *TaskHandler { func NewTaskHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService, logger *zap.Logger, userService platform.UserService) *TaskHandler {
h := &TaskHandler{ h := &TaskHandler{
logger: logger, logger: logger,
Router: NewRouter(), Router: NewRouter(),
UserResourceMappingService: mappingService, UserResourceMappingService: mappingService,
LabelService: labelService, LabelService: labelService,
UserService: userService,
} }
h.HandlerFunc("GET", tasksPath, h.handleGetTasks) h.HandlerFunc("GET", tasksPath, h.handleGetTasks)

View File

@ -112,7 +112,7 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout)) h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout), mock.NewUserService())
h.TaskService = tt.fields.taskService h.TaskService = tt.fields.taskService
h.handleGetTasks(w, r) h.handleGetTasks(w, r)
@ -212,7 +212,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout)) h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout), mock.NewUserService())
h.TaskService = tt.fields.taskService h.TaskService = tt.fields.taskService
h.handlePostTask(w, r) h.handlePostTask(w, r)
@ -316,7 +316,7 @@ func TestTaskHandler_handleGetRun(t *testing.T) {
}, },
})) }))
w := httptest.NewRecorder() w := httptest.NewRecorder()
h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout)) h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout), mock.NewUserService())
h.TaskService = tt.fields.taskService h.TaskService = tt.fields.taskService
h.handleGetRun(w, r) h.handleGetRun(w, r)
@ -424,7 +424,7 @@ func TestTaskHandler_handleGetRuns(t *testing.T) {
}, },
})) }))
w := httptest.NewRecorder() w := httptest.NewRecorder()
h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout)) h := NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), logger.New(os.Stdout), mock.NewUserService())
h.TaskService = tt.fields.taskService h.TaskService = tt.fields.taskService
h.handleGetRuns(w, r) h.handleGetRuns(w, r)

View File

@ -30,7 +30,7 @@ func httpTaskServiceFactory(t *testing.T) (*servicetest.System, context.CancelFu
h := http.NewAuthenticationHandler() h := http.NewAuthenticationHandler()
h.AuthorizationService = i h.AuthorizationService = i
th := http.NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), zaptest.NewLogger(t)) th := http.NewTaskHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), zaptest.NewLogger(t), mock.NewUserService())
th.TaskService = backingTS th.TaskService = backingTS
th.AuthorizationService = i th.AuthorizationService = i
h.Handler = th h.Handler = th

View File

@ -43,6 +43,7 @@ func NewTelegrafHandler(
mappingService platform.UserResourceMappingService, mappingService platform.UserResourceMappingService,
labelService platform.LabelService, labelService platform.LabelService,
telegrafSvc platform.TelegrafConfigStore, telegrafSvc platform.TelegrafConfigStore,
userService platform.UserService,
) *TelegrafHandler { ) *TelegrafHandler {
h := &TelegrafHandler{ h := &TelegrafHandler{
Router: NewRouter(), Router: NewRouter(),
@ -51,6 +52,7 @@ func NewTelegrafHandler(
LabelService: labelService, LabelService: labelService,
TelegrafService: telegrafSvc, TelegrafService: telegrafSvc,
Logger: logger, Logger: logger,
UserService: userService,
} }
h.HandlerFunc("POST", telegrafsPath, h.handlePostTelegraf) h.HandlerFunc("POST", telegrafsPath, h.handlePostTelegraf)
h.HandlerFunc("GET", telegrafsPath, h.handleGetTelegrafs) h.HandlerFunc("GET", telegrafsPath, h.handleGetTelegrafs)

View File

@ -33,11 +33,12 @@ const (
) )
// NewViewHandler returns a new instance of ViewHandler. // NewViewHandler returns a new instance of ViewHandler.
func NewViewHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService) *ViewHandler { func NewViewHandler(mappingService platform.UserResourceMappingService, labelService platform.LabelService, userService platform.UserService) *ViewHandler {
h := &ViewHandler{ h := &ViewHandler{
Router: NewRouter(), Router: NewRouter(),
UserResourceMappingService: mappingService, UserResourceMappingService: mappingService,
LabelService: labelService, LabelService: labelService,
UserService: userService,
} }
h.HandlerFunc("POST", viewsPath, h.handlePostViews) h.HandlerFunc("POST", viewsPath, h.handlePostViews)

View File

@ -129,7 +129,7 @@ func TestService_handleGetViews(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) {
h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.ViewService = tt.fields.ViewService h.ViewService = tt.fields.ViewService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -237,7 +237,7 @@ func TestService_handleGetView(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) {
h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.ViewService = tt.fields.ViewService h.ViewService = tt.fields.ViewService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -342,7 +342,7 @@ func TestService_handlePostViews(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) {
h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.ViewService = tt.fields.ViewService h.ViewService = tt.fields.ViewService
b, err := json.Marshal(tt.args.view) b, err := json.Marshal(tt.args.view)
@ -431,7 +431,7 @@ func TestService_handleDeleteView(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) {
h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.ViewService = tt.fields.ViewService h.ViewService = tt.fields.ViewService
r := httptest.NewRequest("GET", "http://any.url", nil) r := httptest.NewRequest("GET", "http://any.url", nil)
@ -587,7 +587,7 @@ func TestService_handlePatchView(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) {
h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService()) h := NewViewHandler(mock.NewUserResourceMappingService(), mock.NewLabelService(), mock.NewUserService())
h.ViewService = tt.fields.ViewService h.ViewService = tt.fields.ViewService
upd := platform.ViewUpdate{} upd := platform.ViewUpdate{}

View File

@ -8,6 +8,21 @@ import (
var _ platform.UserService = &UserService{} var _ platform.UserService = &UserService{}
// NewUserService returns a mock of NewUserService
// where its methods will return zero values.
func NewUserService() *UserService {
return &UserService{
FindUserByIDFn: func(context.Context, platform.ID) (*platform.User, error) { return nil, nil },
FindUserFn: func(context.Context, platform.UserFilter) (*platform.User, error) { return nil, nil },
CreateUserFn: func(context.Context, *platform.User) error { return nil },
UpdateUserFn: func(context.Context, platform.ID, platform.UserUpdate) (*platform.User, error) { return nil, nil },
DeleteUserFn: func(context.Context, platform.ID) error { return nil },
FindUsersFn: func(context.Context, platform.UserFilter, ...platform.FindOptions) ([]*platform.User, int, error) {
return nil, 0, nil
},
}
}
type UserService struct { type UserService struct {
FindUserByIDFn func(context.Context, platform.ID) (*platform.User, error) FindUserByIDFn func(context.Context, platform.ID) (*platform.User, error)
FindUserFn func(context.Context, platform.UserFilter) (*platform.User, error) FindUserFn func(context.Context, platform.UserFilter) (*platform.User, error)