@@ -3,6 +3,7 @@ package provisioning
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"testing"
7
8
"time"
8
9
@@ -14,6 +15,7 @@ import (
14
15
"github.com/grafana/grafana/pkg/services/org"
15
16
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
16
17
"github.com/grafana/grafana/pkg/services/provisioning/utils"
18
+ "github.com/grafana/grafana/pkg/services/searchV2"
17
19
)
18
20
19
21
func TestProvisioningServiceImpl (t * testing.T ) {
@@ -66,6 +68,27 @@ func TestProvisioningServiceImpl(t *testing.T) {
66
68
// Cancelling the root context and stopping the service
67
69
serviceTest .cancel ()
68
70
})
71
+
72
+ t .Run ("Should not return run error when dashboard provisioning fails" , func (t * testing.T ) {
73
+ serviceTest := setup (t )
74
+ provisioningErr := errors .New ("Test error" )
75
+ serviceTest .mock .ProvisionFunc = func (ctx context.Context ) error {
76
+ return provisioningErr
77
+ }
78
+ err := serviceTest .service .ProvisionDashboards (context .Background ())
79
+ assert .NotNil (t , err )
80
+ serviceTest .startService ()
81
+
82
+ serviceTest .waitForPollChanges ()
83
+ assert .Equal (t , 1 , len (serviceTest .mock .Calls .PollChanges ), "PollChanges should have been called" )
84
+
85
+ // Cancelling the root context and stopping the service
86
+ serviceTest .cancel ()
87
+ serviceTest .waitForStop ()
88
+
89
+ fmt .Println ("serviceTest.serviceError" , serviceTest .serviceError )
90
+ assert .Equal (t , context .Canceled , serviceTest .serviceError )
91
+ })
69
92
}
70
93
71
94
type serviceTestStruct struct {
@@ -95,12 +118,15 @@ func setup(t *testing.T) *serviceTestStruct {
95
118
pollChangesChannel <- ctx
96
119
}
97
120
121
+ searchStub := searchV2 .NewStubSearchService ()
122
+
98
123
serviceTest .service = newProvisioningServiceImpl (
99
124
func (context.Context , string , dashboardstore.DashboardProvisioningService , org.Service , utils.DashboardStore , folder.Service ) (dashboards.DashboardProvisioner , error ) {
100
125
return serviceTest .mock , nil
101
126
},
102
127
nil ,
103
128
nil ,
129
+ searchStub ,
104
130
)
105
131
err := serviceTest .service .setDashboardProvisioner ()
106
132
require .NoError (t , err )
0 commit comments