Skip to content

Commit 1c3db80

Browse files
committed
improve test
1 parent 5a7b72a commit 1c3db80

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

windows/svc/mgr/mgr_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
212222
func 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

Comments
 (0)