@@ -209,6 +209,57 @@ func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) {
209
209
}
210
210
}
211
211
212
+ func testRecoveryActionsOnNonCrashFailures (t * testing.T , s * mgr.Service , should bool ) {
213
+ err := s .SetRecoveryActionsOnNonCrashFailures (should )
214
+ if err != nil {
215
+ t .Fatalf ("SetRecoveryActionsOnNonCrashFailures failed: %v" , err )
216
+ }
217
+ is , err := s .RecoveryActionsOnNonCrashFailures ()
218
+ if err != nil {
219
+ t .Fatalf ("RecoveryActionsOnNonCrashFailures failed: %v" , err )
220
+ }
221
+ if should != is {
222
+ t .Errorf ("RecoveryActionsOnNonCrashFailures mismatch: flag is %v, but should have %v" , is , should )
223
+ }
224
+ }
225
+
226
+ func testMultipleRecoverySettings (t * testing.T , s * mgr.Service , rebootMsgShould , recoveryCmdShould string , actionsFlagShould bool ) {
227
+ err := s .SetRebootMessage (rebootMsgShould )
228
+ if err != nil {
229
+ t .Fatalf ("SetRebootMessage failed: %v" , err )
230
+ }
231
+ err = s .SetRecoveryActionsOnNonCrashFailures (actionsFlagShould )
232
+ if err != nil {
233
+ t .Fatalf ("SetRecoveryActionsOnNonCrashFailures failed: %v" , err )
234
+ }
235
+ err = s .SetRecoveryCommand (recoveryCmdShould )
236
+ if err != nil {
237
+ t .Fatalf ("SetRecoveryCommand failed: %v" , err )
238
+ }
239
+
240
+ rebootMsgIs , err := s .RebootMessage ()
241
+ if err != nil {
242
+ t .Fatalf ("RebootMessage failed: %v" , err )
243
+ }
244
+ if rebootMsgShould != rebootMsgIs {
245
+ t .Errorf ("reboot message mismatch: message is %q, but should have %q" , rebootMsgIs , rebootMsgShould )
246
+ }
247
+ recoveryCommandIs , err := s .RecoveryCommand ()
248
+ if err != nil {
249
+ t .Fatalf ("RecoveryCommand failed: %v" , err )
250
+ }
251
+ if recoveryCmdShould != recoveryCommandIs {
252
+ t .Errorf ("recovery command mismatch: command is %q, but should have %q" , recoveryCommandIs , recoveryCmdShould )
253
+ }
254
+ actionsFlagIs , err := s .RecoveryActionsOnNonCrashFailures ()
255
+ if err != nil {
256
+ t .Fatalf ("RecoveryActionsOnNonCrashFailures failed: %v" , err )
257
+ }
258
+ if actionsFlagShould != actionsFlagIs {
259
+ t .Errorf ("RecoveryActionsOnNonCrashFailures mismatch: flag is %v, but should have %v" , actionsFlagIs , actionsFlagShould )
260
+ }
261
+ }
262
+
212
263
func testControl (t * testing.T , s * mgr.Service , c svc.Cmd , expectedErr error , expectedStatus svc.Status ) {
213
264
status , err := s .Control (c )
214
265
if err != expectedErr {
@@ -305,6 +356,9 @@ func TestMyService(t *testing.T) {
305
356
testRebootMessage (t , s , "" ) // delete reboot message
306
357
testRecoveryCommand (t , s , fmt .Sprintf ("sc query %s" , name ))
307
358
testRecoveryCommand (t , s , "" ) // delete recovery command
359
+ testRecoveryActionsOnNonCrashFailures (t , s , true )
360
+ testRecoveryActionsOnNonCrashFailures (t , s , false )
361
+ testMultipleRecoverySettings (t , s , fmt .Sprintf ("%s failed" , name ), fmt .Sprintf ("sc query %s" , name ), true )
308
362
309
363
expectedStatus := svc.Status {
310
364
State : svc .Stopped ,
0 commit comments