@@ -17,6 +17,7 @@ import (
1717 "testing"
1818 "time"
1919
20+ "golang.org/x/sys/windows"
2021 "golang.org/x/sys/windows/svc"
2122 "golang.org/x/sys/windows/svc/mgr"
2223)
@@ -259,6 +260,16 @@ func testMultipleRecoverySettings(t *testing.T, s *mgr.Service, rebootMsgShould,
259260 }
260261}
261262
263+ func testControl (t * testing.T , s * mgr.Service , c svc.Cmd , expectedErr error , expectedStatus svc.Status ) {
264+ status , err := s .Control (c )
265+ if err != expectedErr {
266+ t .Fatalf ("Unexpected return from s.Control: %v (expected %v)" , err , expectedErr )
267+ }
268+ if expectedStatus != status {
269+ t .Fatalf ("Unexpected status from s.Control: %+v (expected %+v)" , status , expectedStatus )
270+ }
271+ }
272+
262273func remove (t * testing.T , s * mgr.Service ) {
263274 err := s .Delete ()
264275 if err != nil {
@@ -302,6 +313,7 @@ func TestMyService(t *testing.T) {
302313 t .Fatalf ("service %s is not installed" , name )
303314 }
304315 defer s .Close ()
316+ defer s .Delete ()
305317
306318 c .BinaryPathName = exepath
307319 c = testConfig (t , s , c )
@@ -347,6 +359,11 @@ func TestMyService(t *testing.T) {
347359 testRecoveryActionsOnNonCrashFailures (t , s , false )
348360 testMultipleRecoverySettings (t , s , fmt .Sprintf ("%s failed" , name ), fmt .Sprintf ("sc query %s" , name ), true )
349361
362+ expectedStatus := svc.Status {
363+ State : svc .Stopped ,
364+ }
365+ testControl (t , s , svc .Stop , windows .ERROR_SERVICE_NOT_ACTIVE , expectedStatus )
366+
350367 remove (t , s )
351368}
352369
0 commit comments