-
Notifications
You must be signed in to change notification settings - Fork 23
/
async_transport_test.go
99 lines (87 loc) · 2.27 KB
/
async_transport_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package rollbar
import (
"testing"
)
func TestAsyncTransportSend(t *testing.T) {
transport := NewAsyncTransport("", "", 1)
transport.SetLogger(&SilentClientLogger{})
body := map[string]interface{}{
"hello": "world",
}
result := transport.Send(body)
if result != nil {
t.Error("Send returned an unexpected error:", result)
}
transport.Wait()
}
func TestAsyncTransportSendFull(t *testing.T) {
transport := NewAsyncTransport("", "", 0)
transport.SetLogger(&SilentClientLogger{})
body := map[string]interface{}{
"hello": "world",
}
result := transport.Send(body)
if result == nil {
t.Error("Expected to receive ErrBufferFull")
}
transport.Wait()
if transport.perMinCounter != 0 {
t.Error("shouldSend check failed")
}
}
func TestAsyncTransportSendRecover(t *testing.T) {
transport := NewAsyncTransport("", "", 1)
transport.SetLogger(&SilentClientLogger{})
transport.Close()
result := transport.Send(nil)
if result == nil {
t.Error("Expected to receive ErrChannelClosed")
}
transport.Wait()
}
func TestAsyncTransportClose(t *testing.T) {
transport := NewAsyncTransport("", "", 1)
transport.SetLogger(&SilentClientLogger{})
result := transport.Close()
if result != nil {
t.Error("Close returned an unexpected error:", result)
}
}
func TestAsyncTransportSetToken(t *testing.T) {
transport := NewAsyncTransport("", "", 1)
transport.SetLogger(&SilentClientLogger{})
token := "abc"
transport.SetToken(token)
if transport.Token != token {
t.Error("SetToken failed")
}
}
func TestAsyncTransportSetEndpoint(t *testing.T) {
transport := NewAsyncTransport("", "", 1)
transport.SetLogger(&SilentClientLogger{})
endpoint := "https://fake.com"
transport.SetEndpoint(endpoint)
if transport.Endpoint != endpoint {
t.Error("SetEndpoint failed")
}
}
func TestAsyncTransportNotSend(t *testing.T) {
transport := NewAsyncTransport("", "", 2)
transport.SetLogger(&SilentClientLogger{})
transport.SetItemsPerMinute(1)
if transport.ItemsPerMinute != 1 {
t.Error("SetItemsPerMinute failed")
}
body := map[string]interface{}{
"hello": "world",
}
transport.Send(body)
result := transport.Send(body)
if result != nil {
t.Error("Send returned an unexpected error:", result)
}
transport.Wait()
if transport.perMinCounter != 1 {
t.Error("shouldSend check failed")
}
}