mirror of
https://github.com/golang/sys.git
synced 2026-02-09 04:06:04 +03:00
improve test
This commit is contained in:
@@ -209,6 +209,16 @@ func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) {
|
||||
}
|
||||
}
|
||||
|
||||
func testControl(t *testing.T, s *mgr.Service, c svc.Cmd, expectedErr error, expectedStatus svc.Status) {
|
||||
status, err := s.Control(c)
|
||||
if err != expectedErr {
|
||||
t.Fatalf("Unexpected return from s.Control: %v (expected %v)", err, expectedErr)
|
||||
}
|
||||
if expectedStatus != status {
|
||||
t.Fatalf("Unexpected status from s.Control: %+v (expected %+v)", status, expectedStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func remove(t *testing.T, s *mgr.Service) {
|
||||
err := s.Delete()
|
||||
if err != nil {
|
||||
@@ -300,13 +310,7 @@ func TestMyService(t *testing.T) {
|
||||
expectedStatus := svc.Status{
|
||||
State: svc.Stopped,
|
||||
}
|
||||
status, err := s.Control(svc.Stop)
|
||||
if err != windows.ERROR_SERVICE_NOT_ACTIVE {
|
||||
t.Fatalf("Unexpected return from s.Control: %v (expected %v)", err, windows.ERROR_SERVICE_NOT_ACTIVE)
|
||||
}
|
||||
if expectedStatus != status {
|
||||
t.Fatalf("Unexpected status from s.Control: %+v (expected %+v)", status, expectedStatus)
|
||||
}
|
||||
testControl(t, s, svc.Stop, windows.ERROR_SERVICE_NOT_ACTIVE, expectedStatus)
|
||||
|
||||
remove(t, s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user