mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add store split for Get Dashboard version method * Implement dashboard version service * Fix api tests * Remove GetDashboarVersion from sqlstore * Add fakes for Get dashboard version * Fix sqlstore test * Add Get Dashboard store test * Add dashver service test * Remove useless comments
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package dashverimpl
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDashboardVersionService(t *testing.T) {
|
|
dashboardVersionStore := newDashboardVersionStoreFake()
|
|
dashboardVersionService := Service{store: dashboardVersionStore}
|
|
|
|
t.Run("Get dashboard version", func(t *testing.T) {
|
|
dashboard := &dashver.DashboardVersion{
|
|
ID: 11,
|
|
Data: &simplejson.Json{},
|
|
}
|
|
dashboardVersionStore.ExpectedDashboardVersion = dashboard
|
|
dashboardVersion, err := dashboardVersionService.Get(context.Background(), &dashver.GetDashboardVersionQuery{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, dashboardVersion, dashboard)
|
|
})
|
|
}
|
|
|
|
type FakeDashboardVersionStroe struct {
|
|
ExpectedDashboardVersion *dashver.DashboardVersion
|
|
ExpectedError error
|
|
}
|
|
|
|
func newDashboardVersionStoreFake() *FakeDashboardVersionStroe {
|
|
return &FakeDashboardVersionStroe{}
|
|
}
|
|
|
|
func (f *FakeDashboardVersionStroe) Get(ctx context.Context, query *dashver.GetDashboardVersionQuery) (*dashver.DashboardVersion, error) {
|
|
return f.ExpectedDashboardVersion, f.ExpectedError
|
|
}
|