kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2019 AT&T Intellectual Property. |
| 4 | Copyright (c) 2019 Nokia |
| 5 | |
| 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 |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 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. |
wahidw | 761934a | 2019-11-27 06:07:26 +0000 | [diff] [blame] | 17 | |
| 18 | This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | platform project (RICP). |
| 20 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 21 | ================================================================================== |
| 22 | */ |
| 23 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 24 | Mnemonic: rmrpush_test.go |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 25 | Abstract: |
| 26 | Date: 3 May 2019 |
| 27 | */ |
| 28 | package sbi |
| 29 | |
| 30 | import ( |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 31 | //"errors" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 32 | "routing-manager/pkg/rtmgr" |
| 33 | "routing-manager/pkg/stub" |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 34 | "time" |
| 35 | "os" |
| 36 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 37 | "testing" |
| 38 | ) |
| 39 | |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 40 | type Consumer struct{} |
| 41 | |
| 42 | func (m Consumer) Consume(params *xapp.RMRParams) (err error) { |
| 43 | xapp.Sdl.Store("myKey", params.Payload) |
| 44 | return nil |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 45 | } |
| 46 | |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 47 | // Test cases |
| 48 | func TestMain(m *testing.M) { |
| 49 | go xapp.RunWithParams(Consumer{}, false) |
| 50 | time.Sleep(time.Duration(5) * time.Second) |
| 51 | code := m.Run() |
| 52 | os.Exit(code) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* |
| 56 | Resets the EndpointList according to argumnets |
| 57 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 58 | func resetTestPushDataset(instance RmrPush, testdata []rtmgr.Endpoint) { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 59 | rtmgr.Eps = make(map[string]*rtmgr.Endpoint) |
| 60 | for _, endpoint := range testdata { |
| 61 | ep := endpoint |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 62 | //ep.Socket, _ = instance.NewSocket() |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 63 | rtmgr.Eps[ep.Uuid] = &ep |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 68 | rmrpush.Initialize() method is empty, nothing to be tested |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 69 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 70 | func TestRmrPushInitialize(t *testing.T) { |
| 71 | var rmrpush = RmrPush{} |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 72 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 73 | _ = rmrpush.Initialize("") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 77 | rmrpush.Terminate() method is empty, nothing to be tested |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 78 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 79 | func TestRmrPushTerminate(t *testing.T) { |
| 80 | var rmrpush = RmrPush{} |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 81 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 82 | _ = rmrpush.Terminate() |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 86 | rmrpush.UpdateEndpoints() is testd against stub.ValidXApps dataset |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 87 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 88 | func TestRmrPushUpdateEndpoints(t *testing.T) { |
| 89 | var rmrpush = RmrPush{} |
| 90 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 91 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 92 | rmrpush.UpdateEndpoints(&stub.ValidRicComponents) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 93 | if rtmgr.Eps == nil { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 94 | t.Errorf("rmrpush.UpdateEndpoints() result was incorrect, got: %v, want: %v.", nil, "rtmgr.Endpoints") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 99 | rmrpush.AddEndpoint() is tested for happy path case |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 100 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 101 | func TestRmrPushAddEndpoint(t *testing.T) { |
rangajal | d14518e | 2020-04-21 12:33:37 +0000 | [diff] [blame] | 102 | // var err error |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 103 | var rmrpush = RmrPush{} |
| 104 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
| 105 | _ = rmrpush.AddEndpoint(rtmgr.Eps["localhost"]) |
rangajal | d14518e | 2020-04-21 12:33:37 +0000 | [diff] [blame] | 106 | /* if err != nil { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 107 | t.Errorf("rmrpush.AddEndpoint() return was incorrect, got: %v, want: %v.", err, "nil") |
rangajal | d14518e | 2020-04-21 12:33:37 +0000 | [diff] [blame] | 108 | }*/ |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 109 | } |
| 110 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 111 | |
| 112 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 113 | rmrpush.DistributeAll() is tested for happy path case |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 114 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 115 | func TestRmrPushDistributeAll(t *testing.T) { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 116 | var err error |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 117 | var rmrpush = RmrPush{} |
| 118 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 119 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 120 | err = rmrpush.DistributeAll(stub.ValidPolicies) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 121 | if err != nil { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 122 | t.Errorf("rmrpush.DistributeAll(policies) was incorrect, got: %v, want: %v.", err, "nil") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 127 | rmrpush.DistributeToEp() is tested for Sending case |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 128 | */ |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 129 | func TestDistributeToEp(t *testing.T) { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 130 | var err error |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 131 | var rmrpush = RmrPush{} |
| 132 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 133 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 134 | err = rmrpush.DistributeToEp(stub.ValidPolicies,rtmgr.Eps["localhost"]) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 135 | if err != nil { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 136 | t.Errorf("rmrpush.DistributetoEp(policies) was incorrect, got: %v, want: %v.", err, "nil") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 140 | func TestDeleteEndpoint(t *testing.T) { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 141 | var err error |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 142 | var rmrpush = RmrPush{} |
| 143 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 144 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 145 | err = rmrpush.DeleteEndpoint(rtmgr.Eps["localhost"]) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 146 | if err != nil { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 147 | t.Errorf("rmrpush.DeleteEndpoint() was incorrect, got: %v, want: %v.", err, "nil") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
wahidw | 480359e | 2020-04-06 06:56:02 +0000 | [diff] [blame] | 151 | func TestCreateEndpoint(t *testing.T) { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 152 | var rmrpush = RmrPush{} |
| 153 | resetTestPushDataset(rmrpush, stub.ValidEndpoints1) |
wahidw | 7aaff4b | 2020-08-12 13:06:43 +0530 | [diff] [blame] | 154 | rmrpush.CreateEndpoint("192.168.0.1:0","Src=192.168.0.1:4561") |
wahidw | 2e7c3b2 | 2020-08-13 15:59:55 +0530 | [diff] [blame^] | 155 | rmrpush.CreateEndpoint("localhost:4560","Src=192.168.11.1:4444") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 156 | } |
wahidw | 427929c | 2019-12-16 07:02:50 +0000 | [diff] [blame] | 157 | /* |
| 158 | Initialize and send policies |
| 159 | */ |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 160 | func TestRmrPushInitializeandsendPolicies(t *testing.T) { |
| 161 | var rmrpush = RmrPush{} |
| 162 | resetTestPushDataset(rmrpush, stub.ValidEndpoints) |
wahidw | 427929c | 2019-12-16 07:02:50 +0000 | [diff] [blame] | 163 | policies := []string{"hello","welcome"} |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 164 | rmrpush.send_data(rtmgr.Eps["localhost"],&policies,1) |
wahidw | 427929c | 2019-12-16 07:02:50 +0000 | [diff] [blame] | 165 | } |