blob: 9183d3bcf57950386c6a19e9443347816602e5f9 [file] [log] [blame]
Markku Virtanenda34eec2021-05-20 08:22:04 +00001/*
2==================================================================================
3 Copyright (c) 2021 Nokia
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16==================================================================================
17*/
18
19package control
20
21import (
22 "testing"
23
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
25)
26
27func TestRestEndpointOk(t *testing.T) {
28
29 var clientEndpoint models.SubscriptionParamsClientEndpoint
30 var httpPort int64
31 var rmrPort int64
32 var host string
33
34 httpPort = 8080
35 rmrPort = 4560
36 host = "service-ricxapp-xappname-http.ricxapp"
37
38 clientEndpoint.HTTPPort = &httpPort
39 clientEndpoint.RMRPort = &rmrPort
40 clientEndpoint.Host = host
41
42 expectedHttpEndpoint := "service-ricxapp-xappname-http.ricxapp:8080"
43 expectedRmrEndpoint := "service-ricxapp-xappname-rmr.ricxapp:4560"
44
45 httpEndPoint, rmrEndPoint, err := ConstructEndpointAddresses(clientEndpoint)
46
47 if err != nil {
48 t.Errorf("Mismatching return value: %s - ecpected NIL", err)
49 }
50 if httpEndPoint != expectedHttpEndpoint {
Anssi Mannila316d8a12021-06-02 11:08:54 +030051 t.Errorf("Mismatching httpEndpoint: %s - expected %s", httpEndPoint, expectedHttpEndpoint)
Markku Virtanenda34eec2021-05-20 08:22:04 +000052 }
53 if rmrEndPoint != expectedRmrEndpoint {
Anssi Mannila316d8a12021-06-02 11:08:54 +030054 t.Errorf("Mismatching httpEndpoint: %s - expected %s", httpEndPoint, expectedHttpEndpoint)
Markku Virtanenda34eec2021-05-20 08:22:04 +000055 }
56}
57
58func TestRestEndpointNoHttpPort(t *testing.T) {
59
60 var clientEndpoint models.SubscriptionParamsClientEndpoint
61 var httpPort int64
62 var rmrPort int64
63 var host string
64
65 httpPort = 0
66 rmrPort = 4561
67 host = "service-ricxapp-xappname-http.ricxapp"
68
69 clientEndpoint.HTTPPort = &httpPort
70 clientEndpoint.RMRPort = &rmrPort
71 clientEndpoint.Host = host
72
73 expectedHttpEndpoint := ""
74 expectedRmrEndpoint := "service-ricxapp-xappname-rmr.ricxapp:4561"
75
76 httpEndPoint, rmrEndPoint, err := ConstructEndpointAddresses(clientEndpoint)
77
78 if err != nil {
79 t.Errorf("Mismatching return value: %s - ecpected NIL", err)
80 }
81 if httpEndPoint != expectedHttpEndpoint {
82 t.Errorf("Mismatching httpEndpoint: %s - ecpected %s", httpEndPoint, expectedHttpEndpoint)
83 }
84 if rmrEndPoint != expectedRmrEndpoint {
85 t.Errorf("Mismatching httpEndpoint: %s - ecpected %s", httpEndPoint, expectedHttpEndpoint)
86 }
87}
88
89func TestRestEndpointNok(t *testing.T) {
90
91 var clientEndpoint models.SubscriptionParamsClientEndpoint
92 var httpPort int64
93 var rmrPort int64
94 var host string
95
96 httpPort = 0
97 rmrPort = 0
98 host = "service-ricxapp-xappname-http.ricxapp"
99
100 clientEndpoint.HTTPPort = &httpPort
101 clientEndpoint.RMRPort = &rmrPort
102 clientEndpoint.Host = host
103
104 _, _, err := ConstructEndpointAddresses(clientEndpoint)
105
106 if err == nil {
107 t.Errorf("Mismatching return value: - expected ERR but got NIL")
108 }
109}
110
111func TestRestEndpointNoHttpInHost(t *testing.T) {
112
113 var clientEndpoint models.SubscriptionParamsClientEndpoint
114 var httpPort int64
115 var rmrPort int64
116 var host string
117
118 httpPort = 8080
119 rmrPort = 4562
120 host = "service-ricxapp-xappname.ricxapp"
121
122 clientEndpoint.HTTPPort = &httpPort
123 clientEndpoint.RMRPort = &rmrPort
124 clientEndpoint.Host = host
125
126 expectedHttpEndpoint := "service-ricxapp-xappname.ricxapp:8080"
127 expectedRmrEndpoint := "service-ricxapp-xappname.ricxapp:4562"
128
129 httpEndPoint, rmrEndPoint, err := ConstructEndpointAddresses(clientEndpoint)
130
131 if err != nil {
132 t.Errorf("Mismatching return value: %s - ecpected NIL", err)
133 }
134 if httpEndPoint != expectedHttpEndpoint {
135 t.Errorf("Mismatching httpEndpoint: %s - ecpected %s", httpEndPoint, expectedHttpEndpoint)
136 }
137 if rmrEndPoint != expectedRmrEndpoint {
138 t.Errorf("Mismatching httpEndpoint: %s - ecpected %s", httpEndPoint, expectedHttpEndpoint)
139 }
140}
141
142//-----------------------------------------------------------------------------
143//
144//-----------------------------------------------------------------------------