/
broker_test.go
64 lines (47 loc) · 1.06 KB
/
broker_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
package rpc
import (
"testing"
"time"
"go.uber.org/zap"
"gopkg.in/check.v1"
"github.com/eleme/lindb/pkg/logger"
"github.com/eleme/lindb/rpc"
"github.com/eleme/lindb/rpc/proto/common"
)
const (
bindAddress = ":9001"
timeout = time.Second
)
type brokerTestSuite struct {
bs BrokerServer
}
var _ = check.Suite(&brokerTestSuite{
bs: NewBrokerServer(bindAddress),
})
func Test(t *testing.T) {
check.TestingT(t)
}
func (ts *brokerTestSuite) SetUpSuite(c *check.C) {
go func() {
err := ts.bs.Start()
if err != nil {
logger.GetLogger().Error("start broker server error", zap.Error(err))
}
}()
}
func (ts *brokerTestSuite) TearDownSuite(c *check.C) {
ts.bs.Close()
}
func (ts *brokerTestSuite) TestWritePoints(c *check.C) {
cli := NewBrokerClient(bindAddress, timeout)
err := cli.Init()
c.Assert(err, check.IsNil)
resp, err := cli.WritePoints(&common.Request{
Data: []byte("hello"),
})
c.Assert(err, check.IsNil)
c.Assert(resp.Code, check.Equals, rpc.OK)
c.Assert(resp.Msg, check.Equals, "")
err = cli.Close()
c.Assert(err, check.IsNil)
}