-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutil_test.go
77 lines (60 loc) · 1.48 KB
/
util_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
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package netlog
import (
crand "crypto/rand"
"fmt"
"math/rand"
"os"
"path/filepath"
"time"
"comail.io/go/colog"
"github.com/ninibe/bigduration"
)
func init() {
colog.Register()
colog.SetMinLevel(colog.LError)
}
func tempNetLog() *NetLog {
rand.Seed(int64(time.Now().Nanosecond()))
logName := fmt.Sprintf("netlogtest-%d", rand.Int63())
dataDir := filepath.Join(os.TempDir(), logName)
err := os.Mkdir(dataDir, 0777)
panicOn(err)
longTime, err := bigduration.ParseBigDuration("1day")
panicOn(err)
s, err := NewNetLog(dataDir, MonitorInterval(longTime))
panicOn(err)
return s
}
func randMessageSet() []Message {
// random number of payloads with random bytes
data := make([][]byte, rand.Intn(90)+10)
for k := range data {
data[k] = randData(rand.Intn(90) + 10)
}
messages := make([]Message, len(data))
for k := range data {
messages[k] = MessageFromPayload(data[k])
}
return messages
}
var dictionary = "0123456789abcdefghijklmnopqrstuvwxyz"
func randStr(size int) string {
var bytes = randData(size)
for k, v := range bytes {
bytes[k] = dictionary[v%byte(len(dictionary))]
}
return string(bytes)
}
func randData(size int) []byte {
var bytes = make([]byte, size)
_, _ = crand.Read(bytes)
return bytes
}
func panicOn(err error) {
if err != nil {
panic(err)
}
}