@@ -209,6 +209,16 @@ func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) {
209209 }
210210}
211211
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+
212222func remove (t * testing.T , s * mgr.Service ) {
213223 err := s .Delete ()
214224 if err != nil {
@@ -300,13 +310,7 @@ func TestMyService(t *testing.T) {
300310 expectedStatus := svc.Status {
301311 State : svc .Stopped ,
302312 }
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 )
310314
311315 remove (t , s )
312316}
0 commit comments