Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 1 | /* |
| 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 Hyttinen | b31b13f | 2020-03-18 10:25:30 +0200 | [diff] [blame] | 20 | package xapptweaks |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 21 | |
| 22 | import ( |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 23 | "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 24 | "testing" |
| 25 | ) |
| 26 | |
Juha Hyttinen | 8b979ab | 2020-01-14 12:45:48 +0200 | [diff] [blame] | 27 | func TestRmrEndpoint(t *testing.T) { |
| 28 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 29 | tent := teststub.NewTestWrapper("TestRmrEndpoint") |
| 30 | |
Juha Hyttinen | 8b979ab | 2020-01-14 12:45:48 +0200 | [diff] [blame] | 31 | 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 Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 38 | tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort()) |
Juha Hyttinen | 8b979ab | 2020-01-14 12:45:48 +0200 | [diff] [blame] | 39 | return |
| 40 | } |
| 41 | if expect.GetAddr() != res.GetAddr() || expect.GetPort() != res.GetPort() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 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()) |
Juha Hyttinen | 8b979ab | 2020-01-14 12:45:48 +0200 | [diff] [blame] | 43 | } |
| 44 | if expect.String() != res.String() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 45 | tent.TestError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String()) |
Juha Hyttinen | 8b979ab | 2020-01-14 12:45:48 +0200 | [diff] [blame] | 46 | } |
| 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 Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 58 | func TestRmrEndpointList(t *testing.T) { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 59 | |
| 60 | tent := teststub.NewTestWrapper("TestRmrEndpointList") |
| 61 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 62 | epl := &RmrEndpointList{} |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 63 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 64 | // Simple add / has / delete |
| 65 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 66 | tent.TestError(t, "RmrEndpointList: 8080 add failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 67 | } |
| 68 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 69 | tent.TestError(t, "RmrEndpointList: 8080 duplicate add success") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 70 | } |
| 71 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 72 | tent.TestError(t, "RmrEndpointList: 8081 add failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 73 | } |
| 74 | if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 75 | tent.TestError(t, "RmrEndpointList: 8081 has failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 76 | } |
| 77 | if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 78 | tent.TestError(t, "RmrEndpointList: 8081 del failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 79 | } |
| 80 | if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 81 | tent.TestError(t, "RmrEndpointList: 8081 has non existing success") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 82 | } |
| 83 | if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 84 | tent.TestError(t, "RmrEndpointList: 8081 del non existing success") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 85 | } |
| 86 | if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 87 | tent.TestError(t, "RmrEndpointList: 8080 del failed") |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 90 | // list delete |
| 91 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 92 | tent.TestError(t, "RmrEndpointList: 8080 add failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 93 | } |
| 94 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 95 | tent.TestError(t, "RmrEndpointList: 8081 add failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 96 | } |
| 97 | if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 98 | tent.TestError(t, "RmrEndpointList: 8082 add failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | epl2 := &RmrEndpointList{} |
| 102 | if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 103 | tent.TestError(t, "RmrEndpointList: othlist add 9080 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if epl.DelEndpoints(epl2) == true { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 107 | tent.TestError(t, "RmrEndpointList: delete list not existing successs") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 111 | tent.TestError(t, "RmrEndpointList: othlist add 8080 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 112 | } |
| 113 | if epl.DelEndpoints(epl2) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 114 | tent.TestError(t, "RmrEndpointList: delete list 8080,9080 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 118 | tent.TestError(t, "RmrEndpointList: othlist add 8081 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 119 | } |
| 120 | if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 121 | tent.TestError(t, "RmrEndpointList: othlist add 8082 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | if epl.DelEndpoints(epl2) == false { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 125 | tent.TestError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 128 | } |