-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
50 lines (42 loc) · 973 Bytes
/
main_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
package main
import (
"fmt"
"os"
"strings"
"testing"
"time"
log "github.com/sirupsen/logrus"
)
/*
Not the test for main.go. This is the entry point for testing. Package level setup, including fixtures, go here.
Reminder - to test this package, use
go test -tags test
*/
// TestMain provides a mechanism for setting
func TestMain(m *testing.M) {
// env variable defined in constants.go
// LogTestsToFileEnvVar="SG-RESTFUL_LOG_TO_FILE"
logTestsFlag := logTestsEnv()
var f *os.File
if logTestsFlag {
nowtime := time.Now()
timeStr := nowtime.Format("20060102150405")
name := fmt.Sprintf("sg-restful-test.%s.log", timeStr)
f = SetupLogFile(name,
log.DebugLevel,
&log.TextFormatter{})
}
log.Info("TestMain setup")
res := m.Run()
if f != nil {
f.Close()
}
os.Exit(res)
}
func logTestsEnv() bool {
if lt := os.Getenv(LogTestsToFileEnvVar); strings.ToLower(lt) == "true" ||
strings.ToLower(lt) == "yes" {
return true
}
return false
}