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 ==================================================================================
26 func TestRmrEndpoint(t *testing.T) {
28 testEp := func(t *testing.T, val string, expect *RmrEndpoint) {
29 res := NewRmrEndpoint(val)
31 if expect == nil && res == nil {
35 testError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort())
38 if expect.GetAddr() != res.GetAddr() || expect.GetPort() != res.GetPort() {
39 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())
41 if expect.String() != res.String() {
42 testError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String())
47 testEp(t, "localhost:8080", &RmrEndpoint{"localhost", 8080})
48 testEp(t, "127.0.0.1:8080", &RmrEndpoint{"127.0.0.1", 8080})
49 testEp(t, "localhost:70000", nil)
50 testEp(t, "localhost?8080", nil)
51 testEp(t, "abcdefghijklmnopqrstuvwxyz", nil)
55 func TestRmrEndpointList(t *testing.T) {
56 epl := &RmrEndpointList{}
58 // Simple add / has / delete
59 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
60 testError(t, "RmrEndpointList: 8080 add failed")
62 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
63 testError(t, "RmrEndpointList: 8080 duplicate add success")
65 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
66 testError(t, "RmrEndpointList: 8081 add failed")
68 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
69 testError(t, "RmrEndpointList: 8081 has failed")
71 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
72 testError(t, "RmrEndpointList: 8081 del failed")
74 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
75 testError(t, "RmrEndpointList: 8081 has non existing success")
77 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
78 testError(t, "RmrEndpointList: 8081 del non existing success")
80 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
81 testError(t, "RmrEndpointList: 8080 del failed")
85 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
86 testError(t, "RmrEndpointList: 8080 add failed")
88 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
89 testError(t, "RmrEndpointList: 8081 add failed")
91 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
92 testError(t, "RmrEndpointList: 8082 add failed")
95 epl2 := &RmrEndpointList{}
96 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
97 testError(t, "RmrEndpointList: othlist add 9080 failed")
100 if epl.DelEndpoints(epl2) == true {
101 testError(t, "RmrEndpointList: delete list not existing successs")
104 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
105 testError(t, "RmrEndpointList: othlist add 8080 failed")
107 if epl.DelEndpoints(epl2) == false {
108 testError(t, "RmrEndpointList: delete list 8080,9080 failed")
111 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
112 testError(t, "RmrEndpointList: othlist add 8081 failed")
114 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
115 testError(t, "RmrEndpointList: othlist add 8082 failed")
118 if epl.DelEndpoints(epl2) == false {
119 testError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed")