forked from thatguystone/cog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (51 loc) · 1.26 KB
/
main.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
package check
import (
"flag"
"os"
"testing"
"github.com/iheartradio/cog/cfs"
)
//gocovr:skip-file
// Main provides an alternative main for testing. This sets the testing
// environment up and also cleans it up on success; on failure, test files are
// left so that you can better inspect the failure.
//
// If you want to use this functionality, add the following somewhere in your
// tests:
//
// func TestMain(m *testing.M) {
// check.Main(m)
// }
func Main(m *testing.M) {
flag.Parse()
Setup()
code := m.Run()
if code == 0 {
Cleanup()
}
os.Exit(code)
}
// Setup does basic pre-test checks to ensure the environment is ready to run.
// (It's just simple stuff, like make sure DataDir exists, and etc).
//
// This is typically only called from Main(), so you needn't worry about it
// unless you're implementing your own TestMain().
func Setup() {
_, err := cfs.FindDirInParents(DataDir)
if err != nil {
err = os.Mkdir(DataDir, 0750)
}
if err != nil {
panic(err)
}
}
// Cleanup removes any and all testing state
//
// This is typically only called from Main(), so you needn't worry about it
// unless you're implementing your own TestMain().
func Cleanup() {
path, err := cfs.FindDirInParents(DataDir)
if err == nil {
os.RemoveAll(path)
}
}