forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux_formatter_test.go
75 lines (57 loc) · 3.02 KB
/
linux_formatter_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
package disk_test
import (
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-agent/platform/disk"
)
func init() {
Describe("Testing with Ginkgo", func() {
It("linux format when using swap fs", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mkswap", "/dev/xvda1"}))
})
It("linux format when using swap fs and partition is swap", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="swap" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
It("linux format when using ext4 fs with lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))
})
It("linux format when using ext4 fs without lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "/dev/xvda2"}))
})
It("linux format when using ext4 fs and partition is ext4", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemExt4)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
})
}