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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
28 "github.com/stretchr/testify/assert"
39 func TestLogger(t *testing.T){
41 log, err = logger.InitLogger(logger.DebugLevel)
43 t.Errorf("#rmrCgoApi_test.TestLogger - failed to initialize logger, error: %s", err)
45 data := map[string]interface{}{"messageType": 1001, "ranIp":"10.0.0.3", "ranPort": 879, "ranName":"test1"}
46 b := new(bytes.Buffer)
47 _ = json.NewEncoder(b).Encode(data)
48 req := tests.GetHttpRequest()
49 boo, _ := ioutil.ReadAll(req.Body)
50 log.Debugf("#rmrCgoApi_test.TestLogger - request header: %v\n; request body: %s\n", req.Header, string(boo))
54 func TestNewMBufSuccess(t *testing.T) {
56 log, err = logger.InitLogger(logger.DebugLevel)
58 t.Errorf("#rmrCgoApi_test.TestNewMBufSuccess - failed to initialize logger, error: %s", err)
60 msg := NewMBuf(tests.MessageType, len(tests.DummyPayload),"RanName", &tests.DummyPayload, &tests.DummyXAction)
62 assert.NotEmpty(t, msg.Payload)
63 assert.NotEmpty(t, msg.XAction)
64 assert.Equal(t, msg.MType, tests.MessageType)
65 assert.Equal(t, msg.Meid, "RanName")
66 assert.Equal(t, msg.Len, len(tests.DummyPayload))
69 func TestInitFailure(t *testing.T) {
71 log, err = logger.InitLogger(logger.DebugLevel)
73 t.Errorf("#rmrCgoApi_test.TestInitFailure - failed to initialize logger, error: %s", err)
75 go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
76 time.Sleep(time.Second)
78 t.Errorf("The rmr router is ready, should be not ready")
82 //func TestInitSuccess(t *testing.T) {
84 // log, err = logger.InitLogger(true)
86 // t.Errorf("#rmrCgoApi_test.TestInitSuccess - failed to initialize logger, error: %s", err)
88 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
89 // time.Sleep(time.Second)
91 // t.Errorf("The rmr router is not ready, should be ready")
95 func TestIsReadyFailure(t *testing.T) {
97 log, err = logger.InitLogger(logger.InfoLevel)
99 t.Errorf("#rmrCgoApi_test.TestIsReadyFailure - failed to initialize logger, error: %s", err)
102 go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
103 time.Sleep(time.Second)
104 assert.True(t, msgr == nil || !(*msgr).IsReady())
107 //func TestSendRecvMsgSuccess(t *testing.T) {
109 // log, err = logger.InitLogger(true)
111 // t.Errorf("#rmrCgoApi_test.TestSendRecvMsgSuccess - failed to initialize logger, error: %s", err)
113 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
114 // time.Sleep(time.Second)
115 // if msgr == nil || !(*msgr).IsReady() {
116 // t.Errorf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The rmr router is not ready")
118 // msg := NewMBuf(1, tests.MaxMsgSize, &tests.DummyPayload, &tests.DummyXAction)
119 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - Going to send the message: %#v\n", msg)
120 // msgR, _ := (*msgr).SendMsg(msg)
121 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The message has been sent %#v\n", msgR)
122 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The payload: %#v\n", msgR.Payload)
123 // msgR = (*msgr).RecvMsg()
124 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The message has been received: %#v\n", msgR)
125 // log.Debugf("#rmrCgoApi_test.TestSendRecvMsgSuccess - The payload: %#v\n", msgR.Payload)
129 //func TestIsReadySuccess(t *testing.T) {
131 // log, err = logger.InitLogger(true)
133 // t.Errorf("#rmrCgoApi_test.TestIsReadySuccess - The rmr router is not ready")
135 // go initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
136 // time.Sleep(time.Second)
137 // if msgr == nil || !(*msgr).IsReady() {
138 // t.Errorf("#rmrCgoApi_test.TestIsReadySuccess - The rmr router is not ready")
142 func initRmr(port string, maxMsgSize int, flags int, log *logger.Logger){
144 msgr = ctx.Init(port, maxMsgSize, flags, log)