Replace AddHandler with AddHandlerCtx in tests (#42585)
This commit is contained in:
@@ -117,11 +117,11 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
"/api/admin/users/42/enable", "/api/admin/users/:id/enable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
isDisabled := false
|
||||
bus.AddHandler("test", func(cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
isDisabled = cmd.IsDisabled
|
||||
return models.ErrUserNotFound
|
||||
@@ -143,11 +143,11 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
"/api/admin/users/42/disable", "/api/admin/users/:id/disable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
isDisabled := false
|
||||
bus.AddHandler("test", func(cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
isDisabled = cmd.IsDisabled
|
||||
return models.ErrUserNotFound
|
||||
@@ -170,7 +170,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDisableUserScenario(t, "Should return Could not disable external user error", "disable",
|
||||
"/api/admin/users/42/disable", "/api/admin/users/:id/disable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandler("test", func(cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
userID = cmd.UserId
|
||||
return nil
|
||||
})
|
||||
@@ -188,7 +188,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDisableUserScenario(t, "Should return Could not enable external user error", "enable",
|
||||
"/api/admin/users/42/enable", "/api/admin/users/:id/enable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandler("test", func(cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
userID = cmd.UserId
|
||||
return nil
|
||||
})
|
||||
@@ -208,7 +208,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDeleteUserScenario(t, "Should return user not found error", "/api/admin/users/42",
|
||||
"/api/admin/users/:id", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandler("test", func(cmd *models.DeleteUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -25,7 +26,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
editorRole := models.ROLE_EDITOR
|
||||
|
||||
setUp := func(confs ...setUpConf) {
|
||||
bus.AddHandler("test", func(query *models.GetAlertByIdQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertByIdQuery) error {
|
||||
query.Result = singleAlert
|
||||
return nil
|
||||
})
|
||||
@@ -36,12 +37,12 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
aclMockResp = c.aclMockResp
|
||||
}
|
||||
}
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@@ -85,13 +86,13 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
setUp()
|
||||
|
||||
var searchQuery *search.Query
|
||||
bus.AddHandler("test", func(query *search.Query) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *search.Query) error {
|
||||
searchQuery = query
|
||||
return nil
|
||||
})
|
||||
|
||||
var getAlertsQuery *models.GetAlertsQuery
|
||||
bus.AddHandler("test", func(query *models.GetAlertsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
getAlertsQuery = query
|
||||
return nil
|
||||
})
|
||||
@@ -109,7 +110,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
setUp()
|
||||
|
||||
var searchQuery *search.Query
|
||||
bus.AddHandler("test", func(query *search.Query) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *search.Query) error {
|
||||
searchQuery = query
|
||||
query.Result = search.HitList{
|
||||
&search.Hit{ID: 1},
|
||||
@@ -119,7 +120,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
var getAlertsQuery *models.GetAlertsQuery
|
||||
bus.AddHandler("test", func(query *models.GetAlertsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
getAlertsQuery = query
|
||||
return nil
|
||||
})
|
||||
@@ -152,7 +153,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
func callPauseAlert(sc *scenarioContext) {
|
||||
bus.AddHandler("test", func(cmd *models.PauseAlertCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.PauseAlertCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -133,12 +134,12 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
setUp := func() {
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("Given dashboard not exists", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
bus.AddHandler("test", func(query *models.GetDashboardQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
return models.ErrDashboardNotFound
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -44,22 +45,22 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
External: true,
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardSnapshotQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardSnapshotQuery) error {
|
||||
query.Result = mockSnapshotResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.DeleteDashboardSnapshotCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardSnapshotCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
teamResp := []*models.TeamDTO{}
|
||||
bus.AddHandler("test", func(query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = teamResp
|
||||
return nil
|
||||
})
|
||||
|
||||
+21
-21
@@ -108,7 +108,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.FolderId = 1
|
||||
fakeDash.HasAcl = false
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{fakeDash}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@@ -130,12 +130,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@@ -262,7 +262,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
setting.ViewersCanEdit = false
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{fakeDash}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@@ -276,7 +276,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
@@ -287,7 +287,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@@ -391,7 +391,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUpInner := func() *testState {
|
||||
state := setUp()
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@@ -443,7 +443,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@@ -487,7 +487,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
mockResult := []*models.DashboardAclInfoDTO{
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_ADMIN},
|
||||
}
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@@ -537,7 +537,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
mockResult := []*models.DashboardAclInfoDTO{
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@@ -588,7 +588,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
dashTwo.FolderId = 3
|
||||
dashTwo.HasAcl = false
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{dashOne, dashTwo}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@@ -778,12 +778,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
t.Run("Given two dashboards being compared", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
mockResult := []*models.DashboardAclInfoDTO{}
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
Data: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": fmt.Sprintf("Dash%d", query.DashboardId),
|
||||
@@ -841,7 +841,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
DashboardId: 2,
|
||||
Version: 1,
|
||||
@@ -889,7 +889,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
DashboardId: 2,
|
||||
Version: 1,
|
||||
@@ -928,7 +928,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("Given provisioned dashboard", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
bus.AddHandler("test", func(query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
query.Result = []*models.Dashboard{{}}
|
||||
return nil
|
||||
})
|
||||
@@ -947,7 +947,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return &models.DashboardProvisioning{ExternalId: "/tmp/grafana/dashboards/test/dashboard1.json"}, nil
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = []*models.DashboardAclInfoDTO{
|
||||
{OrgId: testOrgID, DashboardId: 1, UserId: testUserID, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
@@ -1049,7 +1049,7 @@ func callGetDashboard(sc *scenarioContext, hs *HTTPServer) {
|
||||
}
|
||||
|
||||
func callGetDashboardVersion(sc *scenarioContext) {
|
||||
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{}
|
||||
return nil
|
||||
})
|
||||
@@ -1059,7 +1059,7 @@ func callGetDashboardVersion(sc *scenarioContext) {
|
||||
}
|
||||
|
||||
func callGetDashboardVersions(sc *scenarioContext) {
|
||||
bus.AddHandler("test", func(query *models.GetDashboardVersionsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionsQuery) error {
|
||||
query.Result = []*models.DashboardVersionDTO{}
|
||||
return nil
|
||||
})
|
||||
@@ -1069,7 +1069,7 @@ func callGetDashboardVersions(sc *scenarioContext) {
|
||||
}
|
||||
|
||||
func callDeleteDashboardBySlug(sc *scenarioContext, hs *HTTPServer) {
|
||||
bus.AddHandler("test", func(cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -1078,7 +1078,7 @@ func callDeleteDashboardBySlug(sc *scenarioContext, hs *HTTPServer) {
|
||||
}
|
||||
|
||||
func callDeleteDashboardByUID(sc *scenarioContext, hs *HTTPServer) {
|
||||
bus.AddHandler("test", func(cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -29,7 +30,7 @@ const (
|
||||
func TestDataSourcesProxy_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/datasources/", func(sc *scenarioContext) {
|
||||
// Stubs the database query
|
||||
bus.AddHandler("test", func(query *models.GetDataSourcesQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDataSourcesQuery) error {
|
||||
assert.Equal(t, testOrgID, query.OrgId)
|
||||
query.Result = []*models.DataSource{
|
||||
{Name: "mmm"},
|
||||
@@ -102,7 +103,7 @@ func TestAddDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
const url = "localhost:5432"
|
||||
|
||||
// Stub handler
|
||||
bus.AddHandler("sql", func(cmd *models.AddDataSourceCommand) error {
|
||||
bus.AddHandlerCtx("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
assert.Equal(t, name, cmd.Name)
|
||||
assert.Equal(t, url, cmd.Url)
|
||||
|
||||
@@ -156,7 +157,7 @@ func TestUpdateDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
const url = "localhost:5432"
|
||||
|
||||
// Stub handler
|
||||
bus.AddHandler("sql", func(cmd *models.AddDataSourceCommand) error {
|
||||
bus.AddHandlerCtx("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
assert.Equal(t, name, cmd.Name)
|
||||
assert.Equal(t, url, cmd.Url)
|
||||
|
||||
@@ -191,26 +192,26 @@ func TestAPI_Datasources_AccessControl(t *testing.T) {
|
||||
Type: "postgresql",
|
||||
Access: "Proxy",
|
||||
}
|
||||
getDatasourceStub := func(query *models.GetDataSourceQuery) error {
|
||||
getDatasourceStub := func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
result := testDatasource
|
||||
result.Id = query.Id
|
||||
result.OrgId = query.OrgId
|
||||
query.Result = &result
|
||||
return nil
|
||||
}
|
||||
getDatasourcesStub := func(cmd *models.GetDataSourcesQuery) error {
|
||||
getDatasourcesStub := func(ctx context.Context, cmd *models.GetDataSourcesQuery) error {
|
||||
cmd.Result = []*models.DataSource{}
|
||||
return nil
|
||||
}
|
||||
addDatasourceStub := func(cmd *models.AddDataSourceCommand) error {
|
||||
addDatasourceStub := func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
cmd.Result = &testDatasource
|
||||
return nil
|
||||
}
|
||||
updateDatasourceStub := func(cmd *models.UpdateDataSourceCommand) error {
|
||||
updateDatasourceStub := func(ctx context.Context, cmd *models.UpdateDataSourceCommand) error {
|
||||
cmd.Result = &testDatasource
|
||||
return nil
|
||||
}
|
||||
deleteDatasourceStub := func(cmd *models.DeleteDataSourceCommand) error {
|
||||
deleteDatasourceStub := func(ctx context.Context, cmd *models.DeleteDataSourceCommand) error {
|
||||
cmd.DeletedDatasourcesCount = 1
|
||||
return nil
|
||||
}
|
||||
@@ -477,7 +478,7 @@ func TestAPI_Datasources_AccessControl(t *testing.T) {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Cleanup(bus.ClearBusHandlers)
|
||||
for i, handler := range test.busStubs {
|
||||
bus.AddHandler(fmt.Sprintf("test_handler_%v", i), handler)
|
||||
bus.AddHandlerCtx(fmt.Sprintf("test_handler_%v", i), handler)
|
||||
}
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
+12
-12
@@ -132,7 +132,7 @@ func TestGetUserFromLDAPAPIEndpoint_OrgNotfound(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
@@ -194,7 +194,7 @@ func TestGetUserFromLDAPAPIEndpoint(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
@@ -269,12 +269,12 @@ func TestGetUserFromLDAPAPIEndpoint_WithTeamHandler(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.GetTeamsForLDAPGroupCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetTeamsForLDAPGroupCommand) error {
|
||||
cmd.Result = []models.TeamOrgGroupDTO{}
|
||||
return nil
|
||||
})
|
||||
@@ -430,7 +430,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_Success(t *testing.T) {
|
||||
Login: "ldap-daniel",
|
||||
}
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
require.Equal(t, "ldap-daniel", cmd.ExternalUser.Login)
|
||||
return nil
|
||||
})
|
||||
@@ -442,7 +442,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_Success(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
require.Equal(t, q.UserId, int64(34))
|
||||
require.Equal(t, q.AuthModule, models.AuthModuleLDAP)
|
||||
|
||||
@@ -510,7 +510,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenGrafanaAdmin(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
require.Equal(t, q.UserId, int64(34))
|
||||
require.Equal(t, q.AuthModule, models.AuthModuleLDAP)
|
||||
|
||||
@@ -542,7 +542,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenUserNotInLDAP(t *testing.T) {
|
||||
|
||||
userSearchResult = nil
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
require.Equal(t, "ldap-daniel", cmd.ExternalUser.Login)
|
||||
return nil
|
||||
})
|
||||
@@ -554,14 +554,14 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenUserNotInLDAP(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(q *models.GetExternalUserInfoByLoginQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetExternalUserInfoByLoginQuery) error {
|
||||
assert.Equal(t, "ldap-daniel", q.LoginOrEmail)
|
||||
q.Result = &models.ExternalUserInfo{IsDisabled: true, UserId: 34}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
assert.Equal(t, 34, cmd.UserId)
|
||||
return nil
|
||||
})
|
||||
@@ -693,11 +693,11 @@ func TestLDAP_AccessControl(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ func TestLoginPostRedirect(t *testing.T) {
|
||||
return hs.LoginPost(c)
|
||||
})
|
||||
|
||||
bus.AddHandler("grafana-auth", func(query *models.LoginUserQuery) error {
|
||||
bus.AddHandlerCtx("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
query.User = &models.User{
|
||||
Id: 42,
|
||||
Email: "",
|
||||
@@ -685,7 +685,7 @@ func TestLoginPostRunLokingHook(t *testing.T) {
|
||||
|
||||
for _, c := range testCases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
bus.AddHandler("grafana-auth", func(query *models.LoginUserQuery) error {
|
||||
bus.AddHandlerCtx("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
query.User = c.authUser
|
||||
query.AuthModule = c.authModule
|
||||
return c.authErr
|
||||
|
||||
@@ -460,7 +460,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("When proxying a datasource that has OAuth token pass-through enabled", func(t *testing.T) {
|
||||
bus.AddHandler("test", func(query *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
query.Result = &models.UserAuth{
|
||||
Id: 1,
|
||||
UserId: 1,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func setUpGetTeamMembersHandler() {
|
||||
bus.AddHandler("test", func(query *models.GetTeamMembersQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamMembersQuery) error {
|
||||
query.Result = []*models.TeamMemberDTO{
|
||||
{Email: "testUser@grafana.com", Login: testUserLogin},
|
||||
{Email: "user1@grafana.com", Login: "user1"},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
@@ -45,7 +46,7 @@ func TestTeamAPIEndpoint(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/teams/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchTeamsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@@ -70,7 +71,7 @@ func TestTeamAPIEndpoint(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/teams/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchTeamsQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -29,7 +30,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
loggedInUserScenario(t, "When calling GET on", "api/users/:id", func(sc *scenarioContext) {
|
||||
fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
|
||||
bus.AddHandler("test", func(query *models.GetUserProfileQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserProfileQuery) error {
|
||||
query.Result = models.UserProfileDTO{
|
||||
Id: int64(1),
|
||||
Email: "daniel@grafana.com",
|
||||
@@ -45,7 +46,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(query *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
query.Result = &models.UserAuth{
|
||||
AuthModule: models.AuthModuleLDAP,
|
||||
}
|
||||
@@ -82,7 +83,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users/lookup", func(sc *scenarioContext) {
|
||||
fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
|
||||
bus.AddHandler("test", func(query *models.GetUserByLoginQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
require.Equal(t, "danlee", query.LoginOrEmail)
|
||||
|
||||
query.Result = &models.User{
|
||||
@@ -129,7 +130,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchUsersQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@@ -153,7 +154,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and limit querystring parameters on", "/api/users", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchUsersQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@@ -173,7 +174,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchUsersQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@@ -199,7 +200,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and perpage querystring parameters on", "/api/users/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandler("test", func(query *models.SearchUsersQuery) error {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
|
||||
Reference in New Issue
Block a user