+ if expect.String() != res.String() {
+ testError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String())
+ }
+
+ }
+
+ testEp(t, "localhost:8080", &RmrEndpoint{"localhost", 8080})
+ testEp(t, "127.0.0.1:8080", &RmrEndpoint{"127.0.0.1", 8080})
+ testEp(t, "localhost:70000", nil)
+ testEp(t, "localhost?8080", nil)
+ testEp(t, "abcdefghijklmnopqrstuvwxyz", nil)
+ testEp(t, "", nil)
+}
+
+func TestRmrEndpointList(t *testing.T) {
+ epl := &RmrEndpointList{}
+
+ // Simple add / has / delete
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
+ testError(t, "RmrEndpointList: 8080 add failed")
+ }
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
+ testError(t, "RmrEndpointList: 8080 duplicate add success")
+ }
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
+ testError(t, "RmrEndpointList: 8081 add failed")
+ }
+ if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
+ testError(t, "RmrEndpointList: 8081 has failed")
+ }
+ if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
+ testError(t, "RmrEndpointList: 8081 del failed")
+ }
+ if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
+ testError(t, "RmrEndpointList: 8081 has non existing success")
+ }
+ if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
+ testError(t, "RmrEndpointList: 8081 del non existing success")
+ }
+ if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
+ testError(t, "RmrEndpointList: 8080 del failed")
+ }
+
+ // list delete
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
+ testError(t, "RmrEndpointList: 8080 add failed")
+ }
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
+ testError(t, "RmrEndpointList: 8081 add failed")
+ }
+ if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
+ testError(t, "RmrEndpointList: 8082 add failed")
+ }
+
+ epl2 := &RmrEndpointList{}
+ if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
+ testError(t, "RmrEndpointList: othlist add 9080 failed")
+ }
+
+ if epl.DelEndpoints(epl2) == true {
+ testError(t, "RmrEndpointList: delete list not existing successs")
+ }
+
+ if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
+ testError(t, "RmrEndpointList: othlist add 8080 failed")
+ }
+ if epl.DelEndpoints(epl2) == false {
+ testError(t, "RmrEndpointList: delete list 8080,9080 failed")
+ }
+
+ if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
+ testError(t, "RmrEndpointList: othlist add 8081 failed")
+ }
+ if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
+ testError(t, "RmrEndpointList: othlist add 8082 failed")
+ }
+
+ if epl.DelEndpoints(epl2) == false {
+ testError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed")