forked from qiniu/logkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_sender_test.go
86 lines (76 loc) · 3.05 KB
/
api_sender_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
package mgr
import (
"net/http"
"github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
"github.com/qiniu/logkit/router"
. "github.com/qiniu/logkit/sender/config"
)
// Rest 测试 端口容易冲突导致混淆,66xx
func senderAPITest(p *testParam) {
t := p.t
rs := p.rs
var got1 respModeUsages
url := "http://127.0.0.1" + rs.address + "/logkit/sender/usages"
respCode, respBody, err := makeRequest(url, http.MethodGet, []byte{})
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got1); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, ModeUsages, got1.Data)
var got2 respModeKeyOptions
url = "http://127.0.0.1" + rs.address + "/logkit/sender/options"
respCode, respBody, err = makeRequest(url, http.MethodGet, []byte{})
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got2); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, ModeKeyOptions, got2.Data)
// Test sender/send with sender config
var got3 respDataMessage
senderConfig := `{
"sampleLog": "[{\"a\": 1}]",
"senders": [{
"name": "mock_sender",
"sender_type": "mock"
}]
}`
url = "http://127.0.0.1" + rs.address + "/logkit/sender/check"
respCode, respBody, err = makeRequest(url, http.MethodPost, []byte(senderConfig))
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got3); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, "", got3.Message)
// Test sender/send with sender config
var got4 respDataMessage
url = "http://127.0.0.1" + rs.address + "/logkit/sender/send"
respCode, respBody, err = makeRequest(url, http.MethodPost, []byte(senderConfig))
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got4); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, "", got4.Message)
var got5 respModeOptions
url = "http://127.0.0.1" + rs.address + "/logkit/sender/router/option"
respCode, respBody, err = makeRequest(url, http.MethodGet, []byte{})
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got5); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, len(router.GetRouterOption()), len(got5.Data))
var got6 respModeUsages
url = "http://127.0.0.1" + rs.address + "/logkit/sender/router/usage"
respCode, respBody, err = makeRequest(url, http.MethodGet, []byte{})
assert.NoError(t, err, string(respBody))
assert.Equal(t, http.StatusOK, respCode)
if err = jsoniter.Unmarshal(respBody, &got6); err != nil {
t.Fatalf("respBody %v unmarshal failed, error is %v", respBody, err)
}
assert.Equal(t, len(router.GetRouterMatchTypeUsage()), len(got6.Data))
}