-
Notifications
You must be signed in to change notification settings - Fork 820
/
testutil.go
71 lines (60 loc) · 1.66 KB
/
testutil.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
package xlsx
import (
"os"
"path/filepath"
qt "github.com/frankban/quicktest"
)
// cleanTempDir removes all the temporary files from NewDiskVCellStore
func cleanTempDir(c *qt.C) {
tempDirBase := os.TempDir()
globPattern := tempDirBase + "/" + cellStorePrefix + "*"
dirs, err := filepath.Glob(globPattern)
if err != nil {
c.Logf("Cannot glob files of %s", globPattern)
c.FailNow()
}
for _, directory := range dirs {
if err = os.RemoveAll(directory); err != nil {
c.Logf("Cannot remove files of %s", directory)
c.FailNow()
}
}
}
// csRunC will run the given test function with all available
// CellStoreConstructors. You must take care of setting the
// CellStoreConstructors on the File struct or whereever else it is needed.
func csRunC(c *qt.C, description string, test func(c *qt.C, constructor CellStoreConstructor)) {
c.Run(description, func(c *qt.C) {
c.Run("MemoryCellStore", func(c *qt.C) {
c.Parallel()
test(c, NewMemoryCellStore)
})
c.Run("DiskVCellStore", func(c *qt.C) {
c.Parallel()
test(c, NewDiskVCellStore)
})
})
c.TB.Cleanup(func() {
if !c.Failed() {
cleanTempDir(c)
}
})
}
// csRunO will run the given test function with all available CellStore FileOptions, you must takes care of passing the FileOption to the appropriate method.
func csRunO(c *qt.C, description string, test func(c *qt.C, option FileOption)) {
c.Run(description, func(c *qt.C) {
c.Run("MemoryCellStore", func(c *qt.C) {
c.Parallel()
test(c, UseMemoryCellStore)
})
c.Run("DiskVCellStore", func(c *qt.C) {
c.Parallel()
test(c, UseDiskVCellStore)
})
})
c.TB.Cleanup(func() {
if !c.Failed() {
cleanTempDir(c)
}
})
}