-
Notifications
You must be signed in to change notification settings - Fork 259
/
Copy pathaudit_test.go
63 lines (54 loc) · 1.38 KB
/
audit_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
package audit
import (
"bytes"
"io/ioutil"
"math/rand"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAudit(t *testing.T) {
dir := "./TestAudit"
audit, err := NewAuditLogger(dir, 5*1024)
assert.NoError(t, err)
defer os.RemoveAll(dir)
for i := 0; i < 1000; i++ {
audit.Log(Message{"haha", time.Now().UnixNano() / 1000000, rand.Int63n(100000000), rand.Int63n(100000), rand.Int63n(100000), "", 123})
time.Sleep(time.Millisecond)
}
files, err := ioutil.ReadDir(dir)
for _, f := range files {
t.Log(f.Name(), " ", f.Size())
}
assert.NoError(t, err)
assert.Equal(t, 9, len(files))
}
//200000 8027 ns/op 208 B/op 1 allocs/op
func BenchmarkAudit(b *testing.B) {
b.ReportAllocs()
dir := "./BenchmarkAudit"
auidt, err := NewAuditLogger(dir, 5*1024*1024)
if err != nil {
b.Error(err)
return
}
defer os.RemoveAll(dir)
for i := 0; i < b.N; i++ {
auidt.Log(Message{"haha", time.Now().UnixNano() / 1000000, 123239232, 123343, 13201200, "", 123})
}
}
func TestIota(t *testing.T) {
buf := bytes.Buffer{}
itoa(&buf, 10)
assert.Equal(t, "10", string(buf.Bytes()))
buf = bytes.Buffer{}
itoa(&buf, 0)
assert.Equal(t, "0", string(buf.Bytes()))
buf = bytes.Buffer{}
itoa(&buf, 123)
assert.Equal(t, "123", string(buf.Bytes()))
buf = bytes.Buffer{}
itoa(&buf, 12322121212121112)
assert.Equal(t, "12322121212121112", string(buf.Bytes()))
}