2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
21 ==================================================================================
24 Mnemonic: nngpush_test.go
32 "routing-manager/pkg/rtmgr"
33 "routing-manager/pkg/stub"
36 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37 //"nanomsg.org/go/mangos/v2"
38 //_ "nanomsg.org/go/mangos/v2/transport/all"
39 //"nanomsg.org/go/mangos/v2/protocol/push"
43 type Consumer struct{}
45 func (m Consumer) Consume(params *xapp.RMRParams) (err error) {
46 xapp.Sdl.Store("myKey", params.Payload)
51 func TestMain(m *testing.M) {
52 go xapp.RunWithParams(Consumer{}, false)
53 time.Sleep(time.Duration(5) * time.Second)
59 Resets the EndpointList according to argumnets
61 func resetTestPushDataset(instance NngPush, testdata []rtmgr.Endpoint) {
62 rtmgr.Eps = make(map[string]*rtmgr.Endpoint)
63 for _, endpoint := range testdata {
65 //ep.Socket, _ = instance.NewSocket()
66 rtmgr.Eps[ep.Uuid] = &ep
71 nngpush.Initialize() method is empty, nothing to be tested
73 func TestNngPushInitialize(t *testing.T) {
74 var nngpush = NngPush{}
76 _ = nngpush.Initialize("")
80 nngpush.Terminate() method is empty, nothing to be tested
82 func TestNngPushTerminate(t *testing.T) {
83 var nngpush = NngPush{}
85 _ = nngpush.Terminate()
89 nngpush.UpdateEndpoints() is testd against stub.ValidXApps dataset
91 func TestNngPushUpdateEndpoints(t *testing.T) {
92 var nngpush = NngPush{}
93 resetTestPushDataset(nngpush, stub.ValidEndpoints)
95 nngpush.UpdateEndpoints(&stub.ValidRicComponents)
97 t.Errorf("nngpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints")
102 nngpush.AddEndpoint() is tested for happy path case
104 func TestNngPushAddEndpoint(t *testing.T) {
106 var nngpush = NngPush{}
107 resetTestPushDataset(nngpush, stub.ValidEndpoints)
108 err = nngpush.AddEndpoint(rtmgr.Eps["localhost"])
110 t.Errorf("nngpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil")
116 nngpush.DistributeAll() is tested for happy path case
118 func TestNngPushDistributeAll(t *testing.T) {
120 var nngpush = NngPush{}
121 resetTestPushDataset(nngpush, stub.ValidEndpoints)
123 err = nngpush.DistributeAll(stub.ValidPolicies)
125 t.Errorf("nngpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil")
130 nngpush.DistributeToEp() is tested for Sending case
132 func TestDistributeToEp(t *testing.T) {
134 var nngpush = NngPush{}
135 resetTestPushDataset(nngpush, stub.ValidEndpoints)
137 err = nngpush.DistributeToEp(stub.ValidPolicies,rtmgr.Eps["localhost"])
139 t.Errorf("nngpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil")
143 func TestDeleteEndpoint(t *testing.T) {
145 var nngpush = NngPush{}
146 resetTestPushDataset(nngpush, stub.ValidEndpoints)
148 err = nngpush.DeleteEndpoint(rtmgr.Eps["localhost"])
150 t.Errorf("nngpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil")
154 func TestCreateEndpoint(t *testing.T) {
155 var nngpush = NngPush{}
156 resetTestPushDataset(nngpush, stub.ValidEndpoints1)
157 nngpush.CreateEndpoint("192.168.0.1:0")
158 nngpush.CreateEndpoint("localhost:4560")
161 Initialize and send policies
163 func TestNngPushInitializeandsendPolicies(t *testing.T) {
164 var nngpush = NngPush{}
165 resetTestPushDataset(nngpush, stub.ValidEndpoints)
166 policies := []string{"hello","welcome"}
167 nngpush.send(rtmgr.Eps["localhost"],&policies)