forked from cloudfoundry/guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmount_options_linux_test.go
88 lines (72 loc) · 2.15 KB
/
mount_options_linux_test.go
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
package rundmc_test
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"code.cloudfoundry.org/guardian/rundmc"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Mount options", func() {
var (
mountPoint string
mountOptions []string
toBeMounted string
getMountOptionsErr error
tmpDir string
)
JustBeforeEach(func() {
mountOptions, getMountOptionsErr = rundmc.GetMountOptions(mountPoint)
})
BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir("", "mountpoint-options")
Expect(err).NotTo(HaveOccurred())
toBeMounted = filepath.Join(tmpDir, "to-be-mounted")
Expect(os.Mkdir(toBeMounted, os.ModeDir)).To(Succeed())
mountPoint = filepath.Join(tmpDir, "mount-point")
Expect(os.Mkdir(mountPoint, os.ModeDir)).To(Succeed())
})
AfterEach(func() {
Expect(os.RemoveAll(tmpDir)).To(Succeed())
})
Context("when the path does not exist", func() {
BeforeEach(func() {
Expect(os.RemoveAll(mountPoint)).To(Succeed())
})
It("returns an error", func() {
Expect(getMountOptionsErr).To(HaveOccurred())
})
})
Context("when the path is not a directory", func() {
BeforeEach(func() {
Expect(os.RemoveAll(mountPoint)).To(Succeed())
_, err := os.Create(mountPoint)
Expect(err).NotTo(HaveOccurred())
})
It("returns an informative error", func() {
Expect(getMountOptionsErr).To(HaveOccurred())
Expect(getMountOptionsErr.Error()).To(ContainSubstring("not a directory"))
})
})
Context("when the path is not mounted", func() {
It("returns an informative error", func() {
Expect(getMountOptionsErr).To(HaveOccurred())
Expect(getMountOptionsErr.Error()).To(ContainSubstring("not a mount point"))
})
})
Context("when the path is a mount point", func() {
BeforeEach(func() {
cmd := exec.Command("mount", "-t", "tmpfs", "-o", "ro,noexec", toBeMounted, mountPoint)
Expect(cmd.Run()).To(Succeed())
})
AfterEach(func() {
cmd := exec.Command("umount", mountPoint)
Expect(cmd.Run()).To(Succeed())
})
It("returns the mount options", func() {
Expect(mountOptions).To(SatisfyAll(ContainElement("ro"), ContainElement("noexec")))
})
})
})