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 ==================================================================================
27 func TestRmrEndpoint1(t *testing.T) {
30 str := fmt.Sprintf("%s:%d", addr, port)
31 Logger.Info("CASE: TestRmrEndpoint1 %s", str)
32 ep := NewRmrEndpoint(str)
33 if ep == nil || ep.Addr != addr || ep.Port != port {
34 t.Errorf("NewRmrEndpoint: %s failed", str)
38 func TestRmrEndpoint2(t *testing.T) {
39 addr := "[2001:2003:fb69:ea00:c894:288b:4582:b5c/64]"
41 str := fmt.Sprintf("%s:%d", addr, port)
42 Logger.Info("CASE: TestRmrEndpoint2 %s", str)
43 ep := NewRmrEndpoint(str)
44 if ep == nil || ep.Addr != addr || ep.Port != port {
45 t.Errorf("NewRmrEndpoint: %s failed", str)
49 func TestRmrEndpoint3(t *testing.T) {
51 str := fmt.Sprintf("%s:port", addr)
52 Logger.Info("CASE: TestRmrEndpoint3 %s", str)
53 ep := NewRmrEndpoint(str)
55 t.Errorf("NewRmrEndpoint: %s successful while should fail", str)
59 func TestRmrEndpoint4(t *testing.T) {
61 str := fmt.Sprintf("%s:port", addr)
62 Logger.Info("CASE: TestRmrEndpoint4 %s", str)
64 if ep.Set(str) == true {
65 t.Errorf("NewRmrEndpoint: Set %s successful while should fail", str)
67 if ep.Addr != "" || ep.Port != 0 {
68 t.Errorf("NewRmrEndpoint: Values %s successful while should fail", str)
72 func TestRmrEndpointList(t *testing.T) {
73 Logger.Info("CASE: TestRmrEndpointList")
75 epl := NewRmrEndpointList()
77 // Simple add / has / delete
78 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
79 t.Errorf("RmrEndpointList: 8080 add failed")
81 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
82 t.Errorf("RmrEndpointList: 8080 duplicate add success")
84 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
85 t.Errorf("RmrEndpointList: 8081 add failed")
87 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
88 t.Errorf("RmrEndpointList: 8081 has failed")
91 Logger.Info("%+v -- %+v -- %d", epl.String(), epl.StringList(), epl.Size())
93 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
94 t.Errorf("RmrEndpointList: 8081 del failed")
96 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
97 t.Errorf("RmrEndpointList: 8081 has non existing success")
99 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
100 t.Errorf("RmrEndpointList: 8081 del non existing success")
102 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
103 t.Errorf("RmrEndpointList: 8080 del failed")
107 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
108 t.Errorf("RmrEndpointList: 8080 add failed")
110 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
111 t.Errorf("RmrEndpointList: 8081 add failed")
113 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
114 t.Errorf("RmrEndpointList: 8082 add failed")
117 epl2 := &RmrEndpointList{}
118 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
119 t.Errorf("RmrEndpointList: othlist add 9080 failed")
122 if epl.DelEndpoints(epl2) == true {
123 t.Errorf("RmrEndpointList: delete list not existing successs")
126 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
127 t.Errorf("RmrEndpointList: othlist add 8080 failed")
129 if epl.DelEndpoints(epl2) == false {
130 t.Errorf("RmrEndpointList: delete list 8080,9080 failed")
133 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
134 t.Errorf("RmrEndpointList: othlist add 8081 failed")
136 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
137 t.Errorf("RmrEndpointList: othlist add 8082 failed")
140 if epl.DelEndpoints(epl2) == false {
141 t.Errorf("RmrEndpointList: delete list 8080,8081,8082,9080 failed")