@@ -209,6 +209,16 @@ func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) {
209
209
}
210
210
}
211
211
212
+ func testControl (t * testing.T , s * mgr.Service , c svc.Cmd , expectedErr error , expectedStatus svc.Status ) {
213
+ status , err := s .Control (c )
214
+ if err != expectedErr {
215
+ t .Fatalf ("Unexpected return from s.Control: %v (expected %v)" , err , expectedErr )
216
+ }
217
+ if expectedStatus != status {
218
+ t .Fatalf ("Unexpected status from s.Control: %+v (expected %+v)" , status , expectedStatus )
219
+ }
220
+ }
221
+
212
222
func remove (t * testing.T , s * mgr.Service ) {
213
223
err := s .Delete ()
214
224
if err != nil {
@@ -300,13 +310,7 @@ func TestMyService(t *testing.T) {
300
310
expectedStatus := svc.Status {
301
311
State : svc .Stopped ,
302
312
}
303
- status , err := s .Control (svc .Stop )
304
- if err != windows .ERROR_SERVICE_NOT_ACTIVE {
305
- t .Fatalf ("Unexpected return from s.Control: %v (expected %v)" , err , windows .ERROR_SERVICE_NOT_ACTIVE )
306
- }
307
- if expectedStatus != status {
308
- t .Fatalf ("Unexpected status from s.Control: %+v (expected %+v)" , status , expectedStatus )
309
- }
313
+ testControl (t , s , svc .Stop , windows .ERROR_SERVICE_NOT_ACTIVE , expectedStatus )
310
314
311
315
remove (t , s )
312
316
}
0 commit comments