-
Notifications
You must be signed in to change notification settings - Fork 6
/
max_valid_uid_test.go
66 lines (52 loc) · 1.29 KB
/
max_valid_uid_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
package idmapper_test
import (
"os"
"path/filepath"
"code.cloudfoundry.org/idmapper"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("MaxValidUid", func() {
var (
workDir string
uidmapPath string
maxUID int
maxValidErr error
)
BeforeEach(func() {
workDir = tempDir("", "")
uidmapPath = filepath.Join(workDir, "uidmap")
writeFile(uidmapPath, []byte("0 0 1\n12345 0 3\n44 0 1"), os.ModePerm)
})
AfterEach(func() {
Expect(os.RemoveAll(workDir)).To(Succeed())
})
JustBeforeEach(func() {
maxUID, maxValidErr = idmapper.IDMap(uidmapPath).MaxValid()
})
It("doesn't fail", func() {
Expect(maxValidErr).NotTo(HaveOccurred())
})
It("returns the largest value", func() {
Expect(maxUID).To(Equal(12347))
})
Context("when the file has no entries", func() {
BeforeEach(func() {
writeFile(uidmapPath, []byte{}, os.ModePerm)
})
It("doesn't fail", func() {
Expect(maxValidErr).NotTo(HaveOccurred())
})
It("should return 0", func() {
Expect(maxUID).To(Equal(0))
})
})
Context("when a line is invalid", func() {
BeforeEach(func() {
writeFile(uidmapPath, []byte("cake"), os.ModePerm)
})
It("returns an error", func() {
Expect(maxValidErr).To(MatchError(`expected integer while parsing line "cake"`))
})
})
})