fe073e98635f61fbf0240ce784126e46dc5a26bf
[ric-plt/xapp-frame.git] / pkg / xapp / rmrendpointlist_test.go
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.
17 ==================================================================================
18 */
19
20 package xapp
21
22 import (
23         "testing"
24 )
25
26 func TestRmrEndpointList(t *testing.T) {
27         Logger.Info("CASE: TestRmrEndpointList")
28
29         epl := NewRmrEndpointList()
30
31         // Simple add / has / delete
32         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
33                 t.Errorf("RmrEndpointList: 8080 add failed")
34         }
35         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
36                 t.Errorf("RmrEndpointList: 8080 duplicate add success")
37         }
38         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
39                 t.Errorf("RmrEndpointList: 8081 add failed")
40         }
41         if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
42                 t.Errorf("RmrEndpointList: 8081 has failed")
43         }
44
45         Logger.Info("%+v -- %+v -- %d", epl.String(), epl.StringList(), epl.Size())
46
47         if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
48                 t.Errorf("RmrEndpointList: 8081 del failed")
49         }
50         if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
51                 t.Errorf("RmrEndpointList: 8081 has non existing success")
52         }
53         if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
54                 t.Errorf("RmrEndpointList: 8081 del non existing success")
55         }
56         if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
57                 t.Errorf("RmrEndpointList: 8080 del failed")
58         }
59
60         // list delete
61         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
62                 t.Errorf("RmrEndpointList: 8080 add failed")
63         }
64         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
65                 t.Errorf("RmrEndpointList: 8081 add failed")
66         }
67         if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
68                 t.Errorf("RmrEndpointList: 8082 add failed")
69         }
70
71         epl2 := &RmrEndpointList{}
72         if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
73                 t.Errorf("RmrEndpointList: othlist add 9080 failed")
74         }
75
76         if epl.DelEndpoints(epl2) == true {
77                 t.Errorf("RmrEndpointList: delete list not existing successs")
78         }
79
80         if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
81                 t.Errorf("RmrEndpointList: othlist add 8080 failed")
82         }
83         if epl.DelEndpoints(epl2) == false {
84                 t.Errorf("RmrEndpointList: delete list 8080,9080 failed")
85         }
86
87         if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
88                 t.Errorf("RmrEndpointList: othlist add 8081 failed")
89         }
90         if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
91                 t.Errorf("RmrEndpointList: othlist add 8082 failed")
92         }
93
94         if epl.DelEndpoints(epl2) == false {
95                 t.Errorf("RmrEndpointList: delete list 8080,8081,8082,9080 failed")
96         }
97
98 }