|
|
|
@ -3,6 +3,7 @@ package provisioning |
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -14,6 +15,7 @@ import ( |
|
|
|
|
"github.com/grafana/grafana/pkg/services/org" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/dashboards" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/utils" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/searchV2" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestProvisioningServiceImpl(t *testing.T) { |
|
|
|
@ -66,6 +68,27 @@ func TestProvisioningServiceImpl(t *testing.T) { |
|
|
|
|
// Cancelling the root context and stopping the service
|
|
|
|
|
serviceTest.cancel() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("Should not return run error when dashboard provisioning fails", func(t *testing.T) { |
|
|
|
|
serviceTest := setup(t) |
|
|
|
|
provisioningErr := errors.New("Test error") |
|
|
|
|
serviceTest.mock.ProvisionFunc = func(ctx context.Context) error { |
|
|
|
|
return provisioningErr |
|
|
|
|
} |
|
|
|
|
err := serviceTest.service.ProvisionDashboards(context.Background()) |
|
|
|
|
assert.NotNil(t, err) |
|
|
|
|
serviceTest.startService() |
|
|
|
|
|
|
|
|
|
serviceTest.waitForPollChanges() |
|
|
|
|
assert.Equal(t, 1, len(serviceTest.mock.Calls.PollChanges), "PollChanges should have been called") |
|
|
|
|
|
|
|
|
|
// Cancelling the root context and stopping the service
|
|
|
|
|
serviceTest.cancel() |
|
|
|
|
serviceTest.waitForStop() |
|
|
|
|
|
|
|
|
|
fmt.Println("serviceTest.serviceError", serviceTest.serviceError) |
|
|
|
|
assert.Equal(t, context.Canceled, serviceTest.serviceError) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type serviceTestStruct struct { |
|
|
|
@ -95,12 +118,15 @@ func setup(t *testing.T) *serviceTestStruct { |
|
|
|
|
pollChangesChannel <- ctx |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
searchStub := searchV2.NewStubSearchService() |
|
|
|
|
|
|
|
|
|
serviceTest.service = newProvisioningServiceImpl( |
|
|
|
|
func(context.Context, string, dashboardstore.DashboardProvisioningService, org.Service, utils.DashboardStore, folder.Service) (dashboards.DashboardProvisioner, error) { |
|
|
|
|
return serviceTest.mock, nil |
|
|
|
|
}, |
|
|
|
|
nil, |
|
|
|
|
nil, |
|
|
|
|
searchStub, |
|
|
|
|
) |
|
|
|
|
err := serviceTest.service.setDashboardProvisioner() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|