blob: e56cea40fd0eb338ec7de20e35c5a9bf42614f9e [file] [log] [blame]
Juha Hyttinene406a342020-01-13 13:02:26 +02001/*
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
Juha Hyttinenb31b13f2020-03-18 10:25:30 +020020package xapptweaks
Juha Hyttinene406a342020-01-13 13:02:26 +020021
22import (
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020023 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
Juha Hyttinene406a342020-01-13 13:02:26 +020024 "testing"
25)
26
Juha Hyttinen8b979ab2020-01-14 12:45:48 +020027func TestRmrEndpoint(t *testing.T) {
28
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020029 tent := teststub.NewTestWrapper("TestRmrEndpoint")
30
Juha Hyttinen8b979ab2020-01-14 12:45:48 +020031 testEp := func(t *testing.T, val string, expect *RmrEndpoint) {
32 res := NewRmrEndpoint(val)
33
34 if expect == nil && res == nil {
35 return
36 }
37 if res == nil {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020038 tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort())
Juha Hyttinen8b979ab2020-01-14 12:45:48 +020039 return
40 }
41 if expect.GetAddr() != res.GetAddr() || expect.GetPort() != res.GetPort() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020042 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())
Juha Hyttinen8b979ab2020-01-14 12:45:48 +020043 }
44 if expect.String() != res.String() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020045 tent.TestError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String())
Juha Hyttinen8b979ab2020-01-14 12:45:48 +020046 }
47
48 }
49
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)
55 testEp(t, "", nil)
56}
57
Juha Hyttinen83ada002020-01-30 10:36:33 +020058func TestRmrEndpointList(t *testing.T) {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020059
60 tent := teststub.NewTestWrapper("TestRmrEndpointList")
61
Juha Hyttinen83ada002020-01-30 10:36:33 +020062 epl := &RmrEndpointList{}
Juha Hyttinene406a342020-01-13 13:02:26 +020063
Juha Hyttinen83ada002020-01-30 10:36:33 +020064 // Simple add / has / delete
65 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020066 tent.TestError(t, "RmrEndpointList: 8080 add failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020067 }
68 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020069 tent.TestError(t, "RmrEndpointList: 8080 duplicate add success")
Juha Hyttinen83ada002020-01-30 10:36:33 +020070 }
71 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020072 tent.TestError(t, "RmrEndpointList: 8081 add failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020073 }
74 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020075 tent.TestError(t, "RmrEndpointList: 8081 has failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020076 }
77 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020078 tent.TestError(t, "RmrEndpointList: 8081 del failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020079 }
80 if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020081 tent.TestError(t, "RmrEndpointList: 8081 has non existing success")
Juha Hyttinen83ada002020-01-30 10:36:33 +020082 }
83 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020084 tent.TestError(t, "RmrEndpointList: 8081 del non existing success")
Juha Hyttinen83ada002020-01-30 10:36:33 +020085 }
86 if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020087 tent.TestError(t, "RmrEndpointList: 8080 del failed")
Juha Hyttinene406a342020-01-13 13:02:26 +020088 }
89
Juha Hyttinen83ada002020-01-30 10:36:33 +020090 // list delete
91 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020092 tent.TestError(t, "RmrEndpointList: 8080 add failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020093 }
94 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020095 tent.TestError(t, "RmrEndpointList: 8081 add failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020096 }
97 if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020098 tent.TestError(t, "RmrEndpointList: 8082 add failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +020099 }
100
101 epl2 := &RmrEndpointList{}
102 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200103 tent.TestError(t, "RmrEndpointList: othlist add 9080 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200104 }
105
106 if epl.DelEndpoints(epl2) == true {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200107 tent.TestError(t, "RmrEndpointList: delete list not existing successs")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200108 }
109
110 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200111 tent.TestError(t, "RmrEndpointList: othlist add 8080 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200112 }
113 if epl.DelEndpoints(epl2) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200114 tent.TestError(t, "RmrEndpointList: delete list 8080,9080 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200115 }
116
117 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200118 tent.TestError(t, "RmrEndpointList: othlist add 8081 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200119 }
120 if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200121 tent.TestError(t, "RmrEndpointList: othlist add 8082 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200122 }
123
124 if epl.DelEndpoints(epl2) == false {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200125 tent.TestError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed")
Juha Hyttinen83ada002020-01-30 10:36:33 +0200126 }
127
Juha Hyttinene406a342020-01-13 13:02:26 +0200128}