-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsession_wh_test.go
58 lines (51 loc) · 1.29 KB
/
session_wh_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
package secureio
import (
"errors"
"math/rand"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
xerrors "github.com/xaionaro-go/errors"
)
func TestHandlerByFuncs_HandleError(t *testing.T) {
h := handlerByFuncs{}
err := errors.New("unit-test")
h.HandleError(err)
callbackCount := 0
h.OnErrorFunc = func(inErr error) {
assert.Equal(t, err, inErr)
callbackCount++
}
h.HandleError(err)
assert.Equal(t, 1, callbackCount)
}
func TestHandlerByFuncs_Handle(t *testing.T) {
h := handlerByFuncs{}
assert.NoError(t, h.Handle(nil))
err := errors.New("unit-test")
b := make([]byte, 10)
rand.Read(b)
h.HandleFunc = func(inBytes []byte) error {
assert.Equal(t, b, inBytes)
return err
}
assert.Equal(t, err, h.Handle(b).(*xerrors.Error).Deepest().Err)
}
func TestSession_checkMessagesChecksum_negative(t *testing.T) {
assert.True(t, (&Session{}).checkMessagesChecksum(
nil,
&messagesContainerHeaders{},
nil,
).(*xerrors.Error).Has(ErrInvalidChecksum{}))
}
func TestSessionIDGetterType_Get(t *testing.T) {
id0 := globalSessionIDGetter.Get()
id1 := globalSessionIDGetter.Get()
timeNowNSec := int64(987654321)
timeNow = func() time.Time {
return time.Unix(123456789, atomic.AddInt64(&timeNowNSec, 1))
}
assert.NotEqual(t, SessionID{}, id0)
assert.NotEqual(t, id0, id1)
}