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
+7 -7
View File
@@ -16,6 +16,7 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
"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/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
@@ -24,7 +25,6 @@ import (
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
"github.com/grafana/grafana/pkg/services/team/teamtest"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/web/webtest"
@@ -76,7 +76,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
assert.Equal(t, 403, sc.resp.Code)
})
mock := mockstore.NewSQLStoreMock()
mock := dbtest.NewFakeDB()
loggedInUserScenarioWithRole(t, "When calling DELETE on", "DELETE", "/api/annotations/1",
"/api/annotations/:annotationId", role, func(sc *scenarioContext) {
sc.handlerFunc = hs.DeleteAnnotationByID
@@ -104,7 +104,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
sc.fakeReqWithParams("PATCH", sc.url, map[string]string{}).exec()
assert.Equal(t, 200, sc.resp.Code)
})
mock := mockstore.NewSQLStoreMock()
mock := dbtest.NewFakeDB()
loggedInUserScenarioWithRole(t, "When calling DELETE on", "DELETE", "/api/annotations/1",
"/api/annotations/:annotationId", role, func(sc *scenarioContext) {
sc.handlerFunc = hs.DeleteAnnotationByID
@@ -177,7 +177,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
sc.fakeReqWithParams("PATCH", sc.url, map[string]string{}).exec()
assert.Equal(t, 403, sc.resp.Code)
})
mock := mockstore.NewSQLStoreMock()
mock := dbtest.NewFakeDB()
loggedInUserScenarioWithRole(t, "When calling DELETE on", "DELETE", "/api/annotations/1",
"/api/annotations/:annotationId", role, func(sc *scenarioContext) {
setUpACL()
@@ -209,7 +209,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
sc.fakeReqWithParams("PATCH", sc.url, map[string]string{}).exec()
assert.Equal(t, 200, sc.resp.Code)
})
mock := mockstore.NewSQLStoreMock()
mock := dbtest.NewFakeDB()
loggedInUserScenarioWithRole(t, "When calling DELETE on", "DELETE", "/api/annotations/1",
"/api/annotations/:annotationId", role, func(sc *scenarioContext) {
setUpACL()
@@ -223,7 +223,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
t.Run("When user is an Admin", func(t *testing.T) {
role := org.RoleAdmin
mockStore := mockstore.NewSQLStoreMock()
mockStore := dbtest.NewFakeDB()
t.Run("Should be able to do anything", func(t *testing.T) {
dashSvc := dashboards.NewFakeDashboardService(t)
@@ -677,7 +677,7 @@ func TestService_AnnotationTypeScopeResolver(t *testing.T) {
func setUpACL() {
viewerRole := org.RoleViewer
editorRole := org.RoleEditor
store := mockstore.NewSQLStoreMock()
store := dbtest.NewFakeDB()
teamSvc := &teamtest.FakeService{}
dashSvc := &dashboards.FakeDashboardService{}
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*models.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {