Chore: Remove mockstore and use dbtest instead (#61629)

* remove mockstore and use dbtest instead

* fix wire

* remove unused expected fields

* fix more tests in alerting

* fix api tests
This commit is contained in:
Serge Zaitsev
2023-01-18 16:01:25 +01:00
committed by GitHub
parent 89e77d072f
commit fa36591380
24 changed files with 80 additions and 236 deletions

View File

@@ -12,12 +12,12 @@ import (
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/db/dbtest"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/auth/authtest"
"github.com/grafana/grafana/pkg/services/login/logintest"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/services/user/usertest"
"github.com/grafana/grafana/pkg/setting"
@@ -148,7 +148,6 @@ func TestAdminAPIEndpoint(t *testing.T) {
t.Run("When a server admin attempts to delete a nonexistent user", func(t *testing.T) {
adminDeleteUserScenario(t, "Should return user not found error", "/api/admin/users/42",
"/api/admin/users/:id", func(sc *scenarioContext) {
sc.sqlStore.(*mockstore.SQLStoreMock).ExpectedError = user.ErrUserNotFound
sc.userService.(*usertest.FakeUserService).ExpectedError = user.ErrUserNotFound
sc.authInfoService.ExpectedError = user.ErrUserNotFound
sc.fakeReqWithParams("DELETE", sc.url, map[string]string{}).exec()
@@ -346,7 +345,7 @@ func adminDisableUserScenario(t *testing.T, desc string, action string, url stri
authInfoService := &logintest.AuthInfoServiceFake{}
hs := HTTPServer{
SQLStore: mockstore.NewSQLStoreMock(),
SQLStore: dbtest.NewFakeDB(),
AuthTokenService: fakeAuthTokenService,
authInfoService: authInfoService,
userService: usertest.NewUserServiceFake(),
@@ -375,7 +374,7 @@ func adminDisableUserScenario(t *testing.T, desc string, action string, url stri
func adminDeleteUserScenario(t *testing.T, desc string, url string, routePattern string, fn scenarioFunc) {
hs := HTTPServer{
SQLStore: mockstore.NewSQLStoreMock(),
SQLStore: dbtest.NewFakeDB(),
userService: usertest.NewUserServiceFake(),
}
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {