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.
17 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
27 func TestRmrEndpoint(t *testing.T) {
29 tent := teststub.NewTestWrapper("TestRmrEndpoint")
31 testEp := func(t *testing.T, val string, expect *RmrEndpoint) {
32 res := NewRmrEndpoint(val)
34 if expect == nil && res == nil {
38 tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort())
41 if expect.GetAddr() != res.GetAddr() || expect.GetPort() != res.GetPort() {
42 tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got addr %s port %d", val, expect.GetAddr(), expect.GetPort(), res.GetAddr(), res.GetPort())
44 if expect.String() != res.String() {
45 tent.TestError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String())
50 testEp(t, "localhost:8080", &RmrEndpoint{"localhost", 8080})
51 testEp(t, "127.0.0.1:8080", &RmrEndpoint{"127.0.0.1", 8080})
52 testEp(t, "localhost:70000", nil)
53 testEp(t, "localhost?8080", nil)
54 testEp(t, "abcdefghijklmnopqrstuvwxyz", nil)
58 func TestRmrEndpointList(t *testing.T) {
60 tent := teststub.NewTestWrapper("TestRmrEndpointList")
62 epl := &RmrEndpointList{}
64 // Simple add / has / delete
65 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
66 tent.TestError(t, "RmrEndpointList: 8080 add failed")
68 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
69 tent.TestError(t, "RmrEndpointList: 8080 duplicate add success")
71 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
72 tent.TestError(t, "RmrEndpointList: 8081 add failed")
74 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
75 tent.TestError(t, "RmrEndpointList: 8081 has failed")
77 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
78 tent.TestError(t, "RmrEndpointList: 8081 del failed")
80 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
81 tent.TestError(t, "RmrEndpointList: 8081 has non existing success")
83 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
84 tent.TestError(t, "RmrEndpointList: 8081 del non existing success")
86 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
87 tent.TestError(t, "RmrEndpointList: 8080 del failed")
91 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
92 tent.TestError(t, "RmrEndpointList: 8080 add failed")
94 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
95 tent.TestError(t, "RmrEndpointList: 8081 add failed")
97 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
98 tent.TestError(t, "RmrEndpointList: 8082 add failed")
101 epl2 := &RmrEndpointList{}
102 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
103 tent.TestError(t, "RmrEndpointList: othlist add 9080 failed")
106 if epl.DelEndpoints(epl2) == true {
107 tent.TestError(t, "RmrEndpointList: delete list not existing successs")
110 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
111 tent.TestError(t, "RmrEndpointList: othlist add 8080 failed")
113 if epl.DelEndpoints(epl2) == false {
114 tent.TestError(t, "RmrEndpointList: delete list 8080,9080 failed")
117 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
118 tent.TestError(t, "RmrEndpointList: othlist add 8081 failed")
120 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
121 tent.TestError(t, "RmrEndpointList: othlist add 8082 failed")
124 if epl.DelEndpoints(epl2) == false {
125 tent.TestError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed")