-
Notifications
You must be signed in to change notification settings - Fork 13
/
fixtures.go
79 lines (63 loc) · 1.48 KB
/
fixtures.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
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package fixtures
import (
"fmt"
"os"
zmq "github.com/pebbe/zmq4"
"github.com/bitmark-inc/bitmarkd/util"
"github.com/bitmark-inc/logger"
)
const (
dir = "testing"
LogCategory = "testing"
)
var (
Listener1 []byte
Listener2 []byte
PublicKey1 []byte
PublicKey2 []byte
PublicKey3 []byte
)
func init() {
c, _ := util.NewConnection("127.0.0.1:1234")
Listener1 = make([]byte, 0, 100)
Listener1 = append(Listener1, c.Pack()...)
c, _ = util.NewConnection("192.168.0.1:5678")
Listener2 = make([]byte, 0, 100)
Listener2 = append(Listener2, c.Pack()...)
tmp, _, _ := zmq.NewCurveKeypair()
PublicKey1 = []byte(zmq.Z85decode(tmp))
tmp, _, _ = zmq.NewCurveKeypair()
PublicKey2 = []byte(zmq.Z85decode(tmp))
tmp, _, _ = zmq.NewCurveKeypair()
PublicKey3 = []byte(zmq.Z85decode(tmp))
}
func SetupTestLogger() {
removeFiles()
_ = os.Mkdir(dir, 0700)
logging := logger.Configuration{
Directory: dir,
File: fmt.Sprintf("%s.log", LogCategory),
Size: 1048576,
Count: 10,
Console: false,
Levels: map[string]string{
logger.DefaultTag: "critical",
},
}
// start logging
_ = logger.Initialise(logging)
}
func TeardownTestLogger() {
logger.Finalise()
removeFiles()
}
func removeFiles() {
err := os.RemoveAll(dir)
if nil != err {
fmt.Println("remove dir with error: ", err)
}
}