grafana/pkg/services/ngalert/state/historian/dashboard_test.go
idafurjes b54b80f473
Chore: Remove Result from dashboard models (#61997)
* Chore: Remove Result from dashboard models

* Fix lint tests

* Fix dashboard service tests

* Fix API tests

* Remove commented out code

* Chore: Merge main - cleanup
2023-01-25 10:36:26 +01:00

42 lines
1.2 KiB
Go

package historian
import (
"context"
"testing"
"time"
"github.com/grafana/grafana/pkg/services/dashboards"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestDashboardResolver(t *testing.T) {
t.Run("fetches dashboards from dashboard service", func(t *testing.T) {
dbs := &dashboards.FakeDashboardService{}
exp := int64(14)
result := &dashboards.Dashboard{ID: exp}
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(result, nil)
sut := createDashboardResolverSut(dbs)
id, err := sut.getID(context.Background(), 1, "dashboard-uid")
require.NoError(t, err)
require.Equal(t, exp, id)
})
t.Run("fetches dashboardNotFound if underlying dashboard does not exist", func(t *testing.T) {
dbs := &dashboards.FakeDashboardService{}
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(nil, dashboards.ErrDashboardNotFound)
sut := createDashboardResolverSut(dbs)
_, err := sut.getID(context.Background(), 1, "not-exist")
require.Error(t, err)
require.ErrorIs(t, err, dashboards.ErrDashboardNotFound)
})
}
func createDashboardResolverSut(dbs *dashboards.FakeDashboardService) *dashboardResolver {
return newDashboardResolver(dbs, 1*time.Nanosecond)
}