-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathexec_process_windows_test.go
More file actions
91 lines (72 loc) · 2.26 KB
/
Copy pathexec_process_windows_test.go
File metadata and controls
91 lines (72 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//go:build windows
// +build windows
package system_test
import (
"fmt"
"os/exec"
"time"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-utils/system"
)
var _ = Describe("execCmdRunner", func() {
var logger boshlog.Logger
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
})
Describe("Start", func() {
It("runs and exits", func() {
command := exec.Command("cmd.exe", "/C", "dir")
process := NewExecProcess(command, false, false, logger)
err := process.Start()
Expect(err).ToNot(HaveOccurred())
result := Result{}
Eventually(process.Wait()).Should(Receive(&result))
Expect(result.Error).ToNot(HaveOccurred())
Expect(result.ExitStatus).To(Equal(0))
})
})
Describe("TerminateNicely", func() {
Context("when process exists", func() {
It("kills the process and returns its exit status", func() {
execProcess := NewExecProcess(exec.Command(windowsExePath), false, false, logger)
err := execProcess.Start()
Expect(err).ToNot(HaveOccurred())
waitCh := execProcess.Wait()
err = execProcess.TerminateNicely(1 * time.Minute)
Expect(err).ToNot(HaveOccurred())
var result Result
select {
case result = <-waitCh:
// ok
case <-time.After(time.Second * 10):
Fail(fmt.Sprintf("TerminateNicely timed out after: %s", time.Second*10), 1)
}
Expect(result.Error).To(HaveOccurred())
Expect(result.ExitStatus).To(Equal(1))
})
})
Context("when process does not exist", func() {
It("returns no error", func() {
execProcess := NewExecProcess(exec.Command(windowsExePath), false, false, logger)
err := execProcess.Start()
Expect(err).ToNot(HaveOccurred())
waitCh := execProcess.Wait()
err = execProcess.TerminateNicely(1 * time.Minute)
Expect(err).ToNot(HaveOccurred())
var result Result
select {
case result = <-waitCh:
// ok
case <-time.After(time.Second * 10):
Fail(fmt.Sprintf("TerminateNicely timed out after: %s", time.Second*10), 1)
}
Expect(result.Error).To(HaveOccurred())
Expect(result.ExitStatus).To(Equal(1))
err = execProcess.TerminateNicely(1 * time.Minute)
Expect(err).ToNot(HaveOccurred())
})
})
})
})