This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
84 lines (69 loc) · 2.9 KB
/
utils_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
package filer_test
import (
"bytes"
"os"
"strings"
"github.com/adelowo/filer"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("Utils", func() {
var _ = DescribeTable("It should remove all numeric characters from the extension",
func(original, expected string) {
Expect(strings.EqualFold(expected,
filer.NormalizeExtension(original))).To(BeTrue())
},
Entry("Single numeric character", "MD1", "MD"),
Entry("Multiple numeric characters", "MD1234", "MD"),
Entry("Multiple numeric characters", "567MD1234", "MD"),
)
var _ = DescribeTable(`
Converting human readable strings to their equivalent in Bytes`,
func(original string, expected int64, hasError bool) {
val, err := filer.LengthInBytes(original)
if hasError {
Expect(err).To(HaveOccurred())
return
}
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal(expected))
},
Entry("Converting an unsupported unit type", "1ZB", int64(-1), true),
Entry("An error should occur when trying to convert a word into an integer",
"twoKB", int64(-1), true),
Entry("Converting Single digit byte", "1B", int64(1), false),
Entry("Converting bytes with a double digit number", "10B", int64(10), false),
Entry("Converting bytes with a BB", "10BB", int64(10), true),
Entry("Converting Single digit Kilobyte", "1KB", int64(1024), false),
Entry("Converting kilobytes with a double digit number", "12KB", int64(12288), false),
Entry("Conversion should not work for 'K' but 'KB' alone", "1K", int64(-1), true),
Entry("Conversion should not work for KBB", "1KBB", int64(-1), true),
Entry("Converting a single digit Megabyte", "1MB", int64(1048576), false),
Entry("Converting a double digit Megabyte", "31MB", int64(32505856), false),
Entry("Conversion should not work for 'M' but 'MB' alone", "31M", int64(-1), true),
Entry("Converting bytes with a MBB", "1MBB", int64(10485676), true),
Entry("Converting a single digit Gigabyte", "1GB", int64(1073741824), false),
Entry("Converting a GBB", "1GBB", int64(-1), true),
Entry("Converting a double digit Gigabyte", "20GB", int64(21474836480), false),
Entry("Conversion should not work for 'G' but 'GB' alone", "1M", int64(-1), true),
Entry("Conversion should not work for 'KBB'", "1KBB", int64(-1), true),
Entry("Conversion should not work for 'GBB'", "1GBB", int64(-1), true),
Entry("Conversion should not work for 'MB'", "MBB", int64(-1), true),
Entry("Conversion should not work for 'TBB'", "TKBB", int64(-1), true),
)
It("Returns the extension when given a file name", func() {
Expect(filer.Extension(&mock{name: "fileName.MD"})).
To(Equal("MD"))
})
})
type mock struct {
name string
}
func (m *mock) Name() string { return m.name }
func (m *mock) Stat() (os.FileInfo, error) {
return nil, &os.PathError{Op: "stat"}
}
func (m *mock) Read(p []byte) (n int, err error) {
return -1, bytes.ErrTooLarge
}