Replace AddHandler with AddHandlerCtx in tests (#42585)

This commit is contained in:
idafurjes
2021-12-01 15:43:31 +01:00
committed by GitHub
parent 2e3fd9d659
commit e6123bc3ef
37 changed files with 173 additions and 162 deletions
+8 -7
View File
@@ -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