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 -8
View File
@@ -43,7 +43,6 @@ import (
"github.com/grafana/grafana/pkg/services/preference/preftest"
"github.com/grafana/grafana/pkg/services/provisioning"
"github.com/grafana/grafana/pkg/services/quota/quotatest"
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
"github.com/grafana/grafana/pkg/services/team/teamtest"
"github.com/grafana/grafana/pkg/services/user"
@@ -733,7 +732,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
})
t.Run("Given a dashboard to validate", func(t *testing.T) {
sqlmock := mockstore.SQLStoreMock{}
sqlmock := dbtest.NewFakeDB()
t.Run("When an invalid dashboard json is posted", func(t *testing.T) {
cmd := dashboards.ValidateDashboardCommand{
@@ -748,7 +747,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
assert.Equal(t, 422, sc.resp.Code)
assert.False(t, result.Get("isValid").MustBool())
assert.NotEmpty(t, result.Get("message").MustString())
}, &sqlmock)
}, sqlmock)
})
t.Run("When a dashboard with a too-low schema version is posted", func(t *testing.T) {
@@ -764,7 +763,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
assert.Equal(t, 412, sc.resp.Code)
assert.False(t, result.Get("isValid").MustBool())
assert.Equal(t, "invalid schema version", result.Get("message").MustString())
}, &sqlmock)
}, sqlmock)
})
t.Run("When a valid dashboard is posted", func(t *testing.T) {
@@ -782,7 +781,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
result := sc.ToJSON()
assert.Equal(t, 200, sc.resp.Code)
assert.True(t, result.Get("isValid").MustBool())
}, &sqlmock)
}, sqlmock)
})
})
@@ -881,7 +880,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
Version: 1,
Data: fakeDash.Data,
}}
mockSQLStore := mockstore.NewSQLStoreMock()
mockSQLStore := dbtest.NewFakeDB()
restoreDashboardVersionScenario(t, "When calling POST on", "/api/dashboards/id/1/restore",
"/api/dashboards/id/:dashboardId/restore", dashboardService, fakeDashboardVersionService, cmd, func(sc *scenarioContext) {
sc.dashboardVersionService = fakeDashboardVersionService
@@ -919,7 +918,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
cmd := dtos.RestoreDashboardVersionCommand{
Version: 1,
}
mockSQLStore := mockstore.NewSQLStoreMock()
mockSQLStore := dbtest.NewFakeDB()
restoreDashboardVersionScenario(t, "When calling POST on", "/api/dashboards/id/1/restore",
"/api/dashboards/id/:dashboardId/restore", dashboardService, fakeDashboardVersionService, cmd, func(sc *scenarioContext) {
callRestoreDashboardVersion(sc)
@@ -928,7 +927,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
})
t.Run("Given provisioned dashboard", func(t *testing.T) {
mockSQLStore := mockstore.NewSQLStoreMock()
mockSQLStore := dbtest.NewFakeDB()
dashboardStore := dashboards.NewFakeDashboardStore(t)
dashboardStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&dashboards.DashboardProvisioning{ExternalID: "/dashboard1.json"}, nil).Once()