Dashboards: Split GetDashboardVersions method (#49967)

* Split GetDashboarVersions method

* Add sqlstore dialect and tests

* Fix signature of PAtchPreference

* Add GetDialect to sqlstore and remove GetDashboardVersions

* Add GetDialect to db interface

* Implement List

* add deleted test function

* Remove GetDialect from sqlstore interface

* Remove deleted method from mock

* Refactor test
This commit is contained in:
idafurjes
2022-06-02 15:59:05 +02:00
committed by GitHub
parent 3e81fa0716
commit bdf50f3dd2
16 changed files with 284 additions and 175 deletions
@@ -53,10 +53,24 @@ func TestDeleteExpiredVersions(t *testing.T) {
})
}
func TestListDashboardVersions(t *testing.T) {
dashboardVersionStore := newDashboardVersionStoreFake()
dashboardVersionService := Service{store: dashboardVersionStore}
t.Run("Get all versions for a given Dashboard ID", func(t *testing.T) {
query := dashver.ListDashboardVersionsQuery{}
dashboardVersionStore.ExpectedListVersions = []*dashver.DashboardVersionDTO{{}}
res, err := dashboardVersionService.List(context.Background(), &query)
require.Nil(t, err)
require.Equal(t, 1, len(res))
})
}
type FakeDashboardVersionStore struct {
ExpectedDashboardVersion *dashver.DashboardVersion
ExptectedDeletedVersions int64
ExpectedVersions []interface{}
ExpectedListVersions []*dashver.DashboardVersionDTO
ExpectedError error
}
@@ -75,3 +89,7 @@ func (f *FakeDashboardVersionStore) GetBatch(ctx context.Context, cmd *dashver.D
func (f *FakeDashboardVersionStore) DeleteBatch(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand, versionIdsToDelete []interface{}) (int64, error) {
return f.ExptectedDeletedVersions, f.ExpectedError
}
func (f *FakeDashboardVersionStore) List(ctx context.Context, query *dashver.ListDashboardVersionsQuery) ([]*dashver.DashboardVersionDTO, error) {
return f.ExpectedListVersions, f.ExpectedError
}