4161f3a5ca
What This commit refactors the logic to restore a dashboard from a version. The logic is moved from the API handler to the dashboard versions service, which now supports restoring dashboards of different API versions. Why To make sure that dashboard version restoration works with v2 dashboards API, as well as future API versions. Signed-off-by: Igor Suleymanov <igor.suleymanov@grafana.com>
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
package dashvertest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
|
)
|
|
|
|
type FakeDashboardVersionService struct {
|
|
ExpectedDashboardVersion *dashver.DashboardVersionDTO
|
|
ExpectedDashboardVersions []*dashver.DashboardVersionDTO
|
|
ExpectedListDashboarVersions []*dashver.DashboardVersionDTO
|
|
ExpectedContinueToken string
|
|
counter int
|
|
ExpectedError error
|
|
// New fields for RestoreVersion testing
|
|
ExpectedRestoreResult *dashboards.Dashboard
|
|
RestoreVersionCalled bool
|
|
LastRestoreCommand *dashver.RestoreVersionCommand
|
|
}
|
|
|
|
func NewDashboardVersionServiceFake() *FakeDashboardVersionService {
|
|
return &FakeDashboardVersionService{}
|
|
}
|
|
|
|
func (f *FakeDashboardVersionService) Get(ctx context.Context, query *dashver.GetDashboardVersionQuery) (*dashver.DashboardVersionDTO, error) {
|
|
if len(f.ExpectedDashboardVersions) == 0 {
|
|
return f.ExpectedDashboardVersion, f.ExpectedError
|
|
}
|
|
f.counter++
|
|
return f.ExpectedDashboardVersions[f.counter-1], f.ExpectedError
|
|
}
|
|
|
|
func (f *FakeDashboardVersionService) DeleteExpired(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand) error {
|
|
return f.ExpectedError
|
|
}
|
|
|
|
func (f *FakeDashboardVersionService) List(ctx context.Context, query *dashver.ListDashboardVersionsQuery) (*dashver.DashboardVersionResponse, error) {
|
|
return &dashver.DashboardVersionResponse{
|
|
ContinueToken: f.ExpectedContinueToken,
|
|
Versions: f.ExpectedListDashboarVersions,
|
|
}, f.ExpectedError
|
|
}
|
|
|
|
func (f *FakeDashboardVersionService) RestoreVersion(ctx context.Context, cmd *dashver.RestoreVersionCommand) (*dashboards.Dashboard, error) {
|
|
f.RestoreVersionCalled = true
|
|
f.LastRestoreCommand = cmd
|
|
return f.ExpectedRestoreResult, f.ExpectedError
|
|
}
|