2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
25 "github.com/stretchr/testify/assert"
36 func TestLogger(t *testing.T){
38 log, err = logger.InitLogger(logger.DebugLevel)
40 t.Errorf("#rmrCgoApi_test.TestLogger - failed to initialize logger, error: %s", err)
42 data := map[string]interface{}{"messageType": 1001, "ranIp":"10.0.0.3", "ranPort": 879, "ranName":"test1"}
43 b := new(bytes.Buffer)
44 _ = json.NewEncoder(b).Encode(data)
45 req := tests.GetHttpRequest()
46 boo, _ := ioutil.ReadAll(req.Body)
47 log.Debugf("#rmrCgoApi_test.TestLogger - request header: %v\n; request body: %s\n", req.Header, string(boo))
51 func TestNewMBufSuccess(t *testing.T) {
53 log, err = logger.InitLogger(logger.DebugLevel)
55 t.Errorf("#rmrCgoApi_test.TestNewMBufSuccess - failed to initialize logger, error: %s", err)
57 msg := NewMBuf(tests.MessageType, len(tests.DummyPayload),"RanName", &tests.DummyPayload, &tests.DummyXAction)
59 assert.NotEmpty(t, msg.Payload)
60 assert.NotEmpty(t, msg.XAction)
61 assert.Equal(t, msg.MType, tests.MessageType)
62 assert.Equal(t, msg.Meid, "RanName")
63 assert.Equal(t, msg.Len, len(tests.DummyPayload))
66 func TestInitFailure(t *testing.T) {
68 log, err = logger.InitLogger(logger.DebugLevel)
70 t.Errorf("#rmrCgoApi_test.TestInitFailure - failed to initialize logger, error: %s", err)
72 go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
73 time.Sleep(time.Second)
75 t.Errorf("The rmr router is ready, should be not ready")
79 //func TestInitSuccess(t *testing.T) {
81 // log, err = logger.InitLogger(true)
83 // t.Errorf("#rmrCgoApi_test.TestInitSuccess - failed to initialize logger, error: %s", err)
85 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
86 // time.Sleep(time.Second)
88 // t.Errorf("The rmr router is not ready, should be ready")
92 func TestIsReadyFailure(t *testing.T) {
94 log, err = logger.InitLogger(logger.InfoLevel)
96 t.Errorf("#rmrCgoApi_test.TestIsReadyFailure - failed to initialize logger, error: %s", err)
99 go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
100 time.Sleep(time.Second)
101 assert.True(t, msgr == nil || !(*msgr).IsReady())
104 //func TestSendRecvMsgSuccess(t *testing.T) {
106 // log, err = logger.InitLogger(true)
108 // t.Errorf("#rmrCgoApi_test.TestSendRecvMsgSuccess - failed to initialize logger, error: %s", err)
110 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
111 // time.Sleep(time.Second)
112 // if msgr == nil || !(*msgr).IsReady() {
113 // t.Errorf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The rmr router is not ready")
115 // msg := NewMBuf(1, tests.MaxMsgSize, &tests.DummyPayload, &tests.DummyXAction)
116 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - Going to send the message: %#v\n", msg)
117 // msgR, _ := (*msgr).SendMsg(msg, tests.MaxMsgSize)
118 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The message has been sent %#v\n", msgR)
119 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The payload: %#v\n", msgR.Payload)
120 // msgR = (*msgr).RecvMsg()
121 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The message has been received: %#v\n", msgR)
122 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The payload: %#v\n", msgR.Payload)
126 //func TestIsReadySuccess(t *testing.T) {
128 // log, err = logger.InitLogger(true)
130 // t.Errorf("#rmrCgoApi_test.TestIsReadySuccess - The rmr router is not ready")
132 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
133 // time.Sleep(time.Second)
134 // if msgr == nil || !(*msgr).IsReady() {
135 // t.Errorf("#rmrCgoApi_test.TestIsReadySuccess - The rmr router is not ready")
139 func initRmr(port string, maxMsgSize int, flags int, log *logger.Logger){
141 msgr = ctx.Init(port, maxMsgSize, flags, log)