eade2aadbe8a724addc9394ed6ddcd626e512927
[ric-plt/submgr.git] / pkg / control / types_test.go
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
20 package control
21
22 import (
23         "testing"
24 )
25
26 func TestRmrEndpoint(t *testing.T) {
27
28         testEp := func(t *testing.T, val string, expect *RmrEndpoint) {
29                 res := NewRmrEndpoint(val)
30
31                 if expect == nil && res == nil {
32                         return
33                 }
34                 if res == nil {
35                         testError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort())
36                         return
37                 }
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())
40                 }
41                 if expect.String() != res.String() {
42                         testError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.Get())
43                 }
44
45         }
46
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)
52         testEp(t, "", nil)
53 }
54
55 func TestAction(t *testing.T) {
56
57         testActionString := func(t *testing.T, val int, str string) {
58                 if Action(val).String() != str {
59                         testError(t, "String for value %d expected %s got %s", val, str, Action(val).String())
60                 }
61         }
62
63         testActionString(t, 0, "CREATE")
64         testActionString(t, 1, "MERGE")
65         testActionString(t, 2, "NONE")
66         testActionString(t, 3, "DELETE")
67         testActionString(t, 5, "UNKNOWN")
68         testActionString(t, 6, "UNKNOWN")
69         testActionString(t, 7, "UNKNOWN")
70         testActionString(t, 10, "UNKNOWN")
71 }