forked from Ptt-official-app/go-pttbbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestinit.go
70 lines (46 loc) · 1.41 KB
/
testinit.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
package main
import (
"os"
"github.com/Ptt-official-app/go-pttbbs/cache"
"github.com/Ptt-official-app/go-pttbbs/cmbbs"
"github.com/Ptt-official-app/go-pttbbs/ptttype"
"github.com/Ptt-official-app/go-pttbbs/types"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
jww "github.com/spf13/jwalterweatherman"
)
var (
origBBSHOME = ""
)
func setupTest() {
jww.SetLogOutput(os.Stderr)
//jww.SetLogThreshold(jww.LevelDebug)
//jww.SetStdoutThreshold(jww.LevelDebug)
log.SetLevel(log.DebugLevel)
cache.SetIsTest()
cmbbs.SetIsTest()
log.Infof("setupTest: to initAllConfig: sem_key: %v", ptttype.PASSWDSEM_KEY)
_ = initAllConfig("./testcase/test.ini")
gin.SetMode(gin.TestMode)
origBBSHOME = ptttype.SetBBSHOME("./testcase")
_ = types.CopyFileToFile("./testcase/.PASSWDS1", "./testcase/.PASSWDS")
_ = types.CopyDirToDir("./testcase/home1", "./testcase/home")
_ = types.CopyDirToDir("./testcase/board1", "./testcase/boards")
_ = cache.NewSHM(types.Key_t(cache.TestShmKey), ptttype.USE_HUGETLB, true)
_ = cache.AttachSHM()
cache.Shm.Reset()
_ = cache.LoadUHash()
cache.ReloadBCache()
_ = cmbbs.PasswdInit()
}
func teardownTest() {
_ = cmbbs.PasswdDestroy()
_ = cache.CloseSHM()
os.Remove("./testcase/.fresh")
os.RemoveAll("./testcase/boards")
os.RemoveAll("./testcase/home")
os.Remove("./testcase/.PASSWDS")
ptttype.SetBBSHOME(origBBSHOME)
cmbbs.UnsetIsTest()
cache.UnsetIsTest()
}