This repository was archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinder_linux_test.go
More file actions
77 lines (63 loc) · 1.49 KB
/
finder_linux_test.go
File metadata and controls
77 lines (63 loc) · 1.49 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
// +build linux
package devoops_test
import (
"os"
"os/exec"
"github.com/glestaris/devoops"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
var _ = Describe("LinuxProcessFinder", func() {
var sess *gexec.Session
BeforeEach(func() {
var err error
path, err := exec.LookPath("sleep")
Expect(err).NotTo(HaveOccurred())
sess, err = gexec.Start(
&exec.Cmd{
Path: path,
Args: []string{"sleep", "100"},
Env: []string{
"banana=best_fruit",
"environ=1",
"hello=world",
},
Dir: "/tmp",
},
GinkgoWriter, GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
sess.Kill()
Expect(sess.Wait()).To(gexec.Exit())
})
Describe("FindByPid", func() {
var pid int
BeforeEach(func() {
pid = sess.Command.Process.Pid
})
It("should return a process with the given environment variables", func() {
proc, err := devoops.FindByPid(pid)
Expect(err).NotTo(HaveOccurred())
Expect(proc.Env).To(ContainElement("banana=best_fruit"))
Expect(proc.Env).To(ContainElement("environ=1"))
Expect(proc.Env).To(ContainElement("hello=world"))
})
It("should return a process with its parent's environment variables "+
"as well",
func() {
proc, err := devoops.FindByPid(pid)
Expect(err).NotTo(HaveOccurred())
Expect(proc.Env).To(ConsistOf(append(
os.Environ(),
[]string{
"banana=best_fruit",
"environ=1",
"hello=world",
}...,
)))
})
})
})