@@ -17,6 +17,7 @@ import (
17
17
"testing"
18
18
"time"
19
19
20
+ "golang.org/x/sys/windows"
20
21
"golang.org/x/sys/windows/svc"
21
22
"golang.org/x/sys/windows/svc/mgr"
22
23
)
@@ -109,7 +110,7 @@ func testRecoveryActions(t *testing.T, s *mgr.Service, should []mgr.RecoveryActi
109
110
if len (should ) != len (is ) {
110
111
t .Errorf ("recovery action mismatch: contains %v actions, but should have %v" , len (is ), len (should ))
111
112
}
112
- for i , _ := range is {
113
+ for i := range is {
113
114
if should [i ].Type != is [i ].Type {
114
115
t .Errorf ("recovery action mismatch: Type is %v, but should have %v" , is [i ].Type , should [i ].Type )
115
116
}
@@ -131,19 +132,19 @@ func testResetPeriod(t *testing.T, s *mgr.Service, should uint32) {
131
132
132
133
func testSetRecoveryActions (t * testing.T , s * mgr.Service ) {
133
134
r := []mgr.RecoveryAction {
134
- mgr. RecoveryAction {
135
+ {
135
136
Type : mgr .NoAction ,
136
137
Delay : 60000 * time .Millisecond ,
137
138
},
138
- mgr. RecoveryAction {
139
+ {
139
140
Type : mgr .ServiceRestart ,
140
141
Delay : 4 * time .Minute ,
141
142
},
142
- mgr. RecoveryAction {
143
+ {
143
144
Type : mgr .ServiceRestart ,
144
145
Delay : time .Minute ,
145
146
},
146
- mgr. RecoveryAction {
147
+ {
147
148
Type : mgr .RunCommand ,
148
149
Delay : 4000 * time .Millisecond ,
149
150
},
@@ -251,6 +252,9 @@ func TestMyService(t *testing.T) {
251
252
t .Fatalf ("service %s is not installed" , name )
252
253
}
253
254
defer s .Close ()
255
+ defer func () {
256
+ _ = s .Delete ()
257
+ }()
254
258
255
259
c .BinaryPathName = exepath
256
260
c = testConfig (t , s , c )
@@ -293,6 +297,17 @@ func TestMyService(t *testing.T) {
293
297
testRecoveryCommand (t , s , fmt .Sprintf ("sc query %s" , name ))
294
298
testRecoveryCommand (t , s , "" ) // delete recovery command
295
299
300
+ expectedStatus := svc.Status {
301
+ State : svc .Stopped ,
302
+ }
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
+ }
310
+
296
311
remove (t , s )
297
312
}
298
313
0 commit comments