blob: 43614918c6406ee4f556bcccb38dd7b146205ac7 [file] [log] [blame]
Mohamed Abukar2e78e422019-06-02 11:45:52 +03001/*
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
20package xapp
21
22import (
23 "github.com/gorilla/mux"
Juha Hyttinen3cfee962020-02-13 13:51:00 +020024 "github.com/spf13/viper"
Mohamed Abukar2e78e422019-06-02 11:45:52 +030025 "net/http"
26 "net/http/httptest"
Mohamed Abukared119192020-11-19 14:38:22 +020027 "github.com/stretchr/testify/assert"
Mohamed Abukar2e78e422019-06-02 11:45:52 +030028 "os"
29 "strings"
30 "testing"
31 "time"
Mohamed Abukared119192020-11-19 14:38:22 +020032 "bytes"
Mohamed Abukar2e78e422019-06-02 11:45:52 +030033)
34
Juha Hyttinen3cfee962020-02-13 13:51:00 +020035//var _ = func() bool {
36// testing.Init()
37// return true
38//}()
Mohamed Abukar5120ec12020-02-04 11:01:24 +020039
Juha Hyttinen3cfee962020-02-13 13:51:00 +020040type Consumer struct{}
Mohamed Abukar2e78e422019-06-02 11:45:52 +030041
Mohamed Abukarf11ab7a2019-08-14 16:55:01 +030042func (m Consumer) Consume(params *RMRParams) (err error) {
Mohamed Abukarf11ab7a2019-08-14 16:55:01 +030043 Sdl.Store("myKey", params.Payload)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030044 return nil
45}
46
47// Test cases
48func TestMain(m *testing.M) {
Mohamed Abukar827a6412020-11-12 10:02:41 +020049 go RunWithParams(Consumer{}, viper.GetBool("controls.waitForSdl"))
Mohamed Abukar5120ec12020-02-04 11:01:24 +020050 time.Sleep(time.Duration(5) * time.Second)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030051 code := m.Run()
52 os.Exit(code)
53}
54
55func TestGetHealthCheckRetursServiceUnavailableError(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +030056 Logger.Info("CASE: TestGetHealthCheckRetursServiceUnavailableError")
Mohamed Abukar2e78e422019-06-02 11:45:52 +030057 req, _ := http.NewRequest("GET", "/ric/v1/health/ready", nil)
Mohamed Abukared119192020-11-19 14:38:22 +020058 /*response :=*/ executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030059
Mohamed Abukar5120ec12020-02-04 11:01:24 +020060 //checkResponseCode(t, http.StatusServiceUnavailable, response.Code)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030061}
62
63func TestGetHealthCheckReturnsSuccess(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +030064 Logger.Info("CASE: TestGetHealthCheckReturnsSuccess")
Mohamed Abukar2e78e422019-06-02 11:45:52 +030065 for Rmr.IsReady() == false {
66 time.Sleep(time.Duration(2) * time.Second)
67 }
68
69 req, _ := http.NewRequest("GET", "/ric/v1/health/ready", nil)
Mohamed Abukared119192020-11-19 14:38:22 +020070 response := executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030071
72 checkResponseCode(t, http.StatusOK, response.Code)
73}
74
75func TestInjectQuerySinglePath(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +030076 Logger.Info("CASE: TestInjectQuerySinglePath")
Mohamed Abukar2e78e422019-06-02 11:45:52 +030077 var handler = func(w http.ResponseWriter, r *http.Request) {
78 }
79
80 Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar")
81
82 req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar", nil)
Mohamed Abukared119192020-11-19 14:38:22 +020083 response := executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030084 checkResponseCode(t, http.StatusOK, response.Code)
85}
86
87func TestInjectQueryMultiplePaths(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +030088 Logger.Info("CASE: TestInjectQueryMultiplePaths")
Mohamed Abukar2e78e422019-06-02 11:45:52 +030089 var handler = func(w http.ResponseWriter, r *http.Request) {
90 }
91
92 Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
93
94 req, _ := http.NewRequest("GET", "/ric/v1/user?foo=bar&id=mykey", nil)
Mohamed Abukared119192020-11-19 14:38:22 +020095 response := executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +030096 checkResponseCode(t, http.StatusOK, response.Code)
97}
98
99func TestInjectQueryFailures(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300100 Logger.Info("CASE: TestInjectQueryFailures")
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300101 var handler = func(w http.ResponseWriter, r *http.Request) {
102 }
103
104 Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
105
106 req, _ := http.NewRequest("GET", "/ric/v1/user?invalid=bar&no=mykey", nil)
Mohamed Abukared119192020-11-19 14:38:22 +0200107 response := executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300108 checkResponseCode(t, http.StatusNotFound, response.Code)
109}
110
111func TestMessagesReceivedSuccessfully(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300112 Logger.Info("CASE: TestMessagesReceivedSuccessfully")
Mohamed Abukar9568a2d2020-02-18 16:50:32 +0200113 time.Sleep(time.Duration(5) * time.Second)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300114 for i := 0; i < 100; i++ {
Mohamed Abukarf11ab7a2019-08-14 16:55:01 +0300115 params := &RMRParams{}
116 params.Mtype = 10004
117 params.SubId = -1
118 params.Payload = []byte{1, 2, 3, 4, 5, 6}
Mohamed Abukar19461e12019-08-23 08:46:11 +0300119 params.Meid = &RMRMeid{PlmnID: "1234", EnbID: "7788", RanName: "RanName-1234"}
Mohamed Abukarf11ab7a2019-08-14 16:55:01 +0300120 params.Xid = "TestXID"
Mohamed Abukared119192020-11-19 14:38:22 +0200121
122 if i % 2 == 0 {
123 Rmr.SendMsg(params)
124 } else {
125 Rmr.SendWithRetry(params, false, 1)
126 }
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300127 }
Mohamed Abukared119192020-11-19 14:38:22 +0200128 Rmr.RegisterMetrics()
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300129
130 // Allow time to process the messages
Juha Hyttinenf619d032020-05-07 12:42:26 +0300131 time.Sleep(time.Duration(5) * time.Second)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300132
Mohamed Abukar827a6412020-11-12 10:02:41 +0200133 waitForSdl := viper.GetBool("controls.waitForSdl")
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300134 stats := getMetrics(t)
135 if !strings.Contains(stats, "ricxapp_RMR_Transmitted 100") {
Mohamed Abukar9568a2d2020-02-18 16:50:32 +0200136 t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300137 }
138
139 if !strings.Contains(stats, "ricxapp_RMR_Received 100") {
Mohamed Abukar9568a2d2020-02-18 16:50:32 +0200140 t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300141 }
142
143 if !strings.Contains(stats, "ricxapp_RMR_TransmitError 0") {
144 t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect")
145 }
146
147 if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") {
148 t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect")
149 }
150
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200151 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 100") {
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300152 t.Errorf("Error: ricxapp_SDL_Stored value incorrect")
153 }
154
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200155 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") {
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300156 t.Errorf("Error: ricxapp_SDL_StoreError value incorrect")
157 }
158}
159
wahidwad0a2712020-03-04 09:54:15 +0000160func TestMessagesReceivedSuccessfullyUsingWh(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300161 Logger.Info("CASE: TestMessagesReceivedSuccessfullyUsingWh")
wahidwad0a2712020-03-04 09:54:15 +0000162 time.Sleep(time.Duration(5) * time.Second)
163 whid := Rmr.Openwh("localhost:4560")
164 time.Sleep(time.Duration(1) * time.Second)
165 for i := 0; i < 100; i++ {
166 params := &RMRParams{}
167 params.Mtype = 10004
168 params.SubId = -1
169 params.Payload = []byte{1, 2, 3, 4, 5, 6}
170 params.Meid = &RMRMeid{PlmnID: "1234", EnbID: "7788", RanName: "RanName-1234"}
171 params.Xid = "TestXID"
172 params.Whid = int(whid)
Mohamed Abukared119192020-11-19 14:38:22 +0200173
174 if i == 0 {
175 Logger.Info("%+v", params.String())
176 }
177
wahidwad0a2712020-03-04 09:54:15 +0000178 Rmr.SendMsg(params)
179 }
180
181 // Allow time to process the messages
Juha Hyttinenf619d032020-05-07 12:42:26 +0300182 time.Sleep(time.Duration(5) * time.Second)
wahidwad0a2712020-03-04 09:54:15 +0000183
Mohamed Abukar827a6412020-11-12 10:02:41 +0200184 waitForSdl := viper.GetBool("controls.waitForSdl")
wahidwad0a2712020-03-04 09:54:15 +0000185 stats := getMetrics(t)
186 if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") {
187 t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
188 }
189
190 if !strings.Contains(stats, "ricxapp_RMR_Received 200") {
191 t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats)
192 }
193
194 if !strings.Contains(stats, "ricxapp_RMR_TransmitError 0") {
195 t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect")
196 }
197
198 if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") {
199 t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect")
200 }
201
202 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 200") {
203 t.Errorf("Error: ricxapp_SDL_Stored value incorrect")
204 }
205
206 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") {
207 t.Errorf("Error: ricxapp_SDL_StoreError value incorrect")
208 }
209 Rmr.Closewh(int(whid))
210}
211
wahidwe0948fe2020-03-19 14:49:41 +0000212func TestMessagesReceivedSuccessfullyUsingWhCall(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300213 Logger.Info("CASE: TestMessagesReceivedSuccessfullyUsingWhCall")
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300214 time.Sleep(time.Duration(5) * time.Second)
215 whid := Rmr.Openwh("localhost:4560")
216 params := &RMRParams{}
217 params.Payload = []byte("newrt|start\nnewrt|end\n")
218 params.Whid = int(whid)
219 params.Callid = 4
220 params.Timeout = 1000
221 Rmr.SendCallMsg(params)
wahidwe0948fe2020-03-19 14:49:41 +0000222
223 // Allow time to process the messages
224 time.Sleep(time.Duration(2) * time.Second)
225
Mohamed Abukar827a6412020-11-12 10:02:41 +0200226 waitForSdl := viper.GetBool("controls.waitForSdl")
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300227 stats := getMetrics(t)
228 if !strings.Contains(stats, "ricxapp_RMR_Transmitted 200") {
229 t.Errorf("Error: ricxapp_RMR_Transmitted value incorrect: %v", stats)
230 }
wahidwe0948fe2020-03-19 14:49:41 +0000231
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300232 if !strings.Contains(stats, "ricxapp_RMR_Received 201") {
233 t.Errorf("Error: ricxapp_RMR_Received value incorrect: %v", stats)
234 }
wahidwe0948fe2020-03-19 14:49:41 +0000235
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300236 if !strings.Contains(stats, "ricxapp_RMR_TransmitError 1") {
237 t.Errorf("Error: ricxapp_RMR_TransmitError value incorrect")
238 }
wahidwe0948fe2020-03-19 14:49:41 +0000239
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300240 if !strings.Contains(stats, "ricxapp_RMR_ReceiveError 0") {
241 t.Errorf("Error: ricxapp_RMR_ReceiveError value incorrect")
242 }
wahidwe0948fe2020-03-19 14:49:41 +0000243
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300244 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_Stored 201") {
245 t.Errorf("Error: ricxapp_SDL_Stored value incorrect")
246 }
wahidwe0948fe2020-03-19 14:49:41 +0000247
Mohamed Abukar5953f7e2020-04-02 10:08:14 +0300248 if waitForSdl && !strings.Contains(stats, "ricxapp_SDL_StoreError 0") {
249 t.Errorf("Error: ricxapp_SDL_StoreError value incorrect")
250 }
251 Rmr.Closewh(int(whid))
wahidwe0948fe2020-03-19 14:49:41 +0000252}
253
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300254func TestSubscribeChannels(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300255 Logger.Info("CASE: TestSubscribeChannels")
Mohamed Abukar827a6412020-11-12 10:02:41 +0200256 if !viper.GetBool("controls.waitForSdl") {
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200257 return
258 }
259
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300260 var NotificationCb = func(ch string, events ...string) {
261 if ch != "channel1" {
262 t.Errorf("Error: Callback function called with incorrect params")
263 }
264 }
265
266 if err := Sdl.Subscribe(NotificationCb, "channel1"); err != nil {
267 t.Errorf("Error: Subscribe failed: %v", err)
268 }
269 time.Sleep(time.Duration(2) * time.Second)
270
271 if err := Sdl.StoreAndPublish("channel1", "event", "key1", "data1"); err != nil {
272 t.Errorf("Error: Publish failed: %v", err)
273 }
Mohamed Abukared119192020-11-19 14:38:22 +0200274
275 // Misc.
276 Sdl.MStoreAndPublish([]string{"channel1"}, "event", "key1", "data1")
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300277}
278
Mohamed Abukar775722c2019-06-10 16:41:57 +0300279func TestGetRicMessageSuccess(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300280 Logger.Info("CASE: TestGetRicMessageSuccess")
Mohamed Abukar775722c2019-06-10 16:41:57 +0300281 id, ok := Rmr.GetRicMessageId("RIC_SUB_REQ")
282 if !ok || id != 12010 {
283 t.Errorf("Error: GetRicMessageId failed: id=%d", id)
284 }
285
286 name := Rmr.GetRicMessageName(12010)
Mohamed Abukar3e611c62019-07-05 13:40:11 +0300287 if name != "RIC_SUB_REQ" {
Mohamed Abukar775722c2019-06-10 16:41:57 +0300288 t.Errorf("Error: GetRicMessageName failed: name=%s", name)
289 }
290}
291
292func TestGetRicMessageFails(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300293 Logger.Info("CASE: TestGetRicMessageFails")
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200294 ok := Rmr.IsRetryError(&RMRParams{status: 0})
Mohamed Abukar775722c2019-06-10 16:41:57 +0300295 if ok {
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200296 t.Errorf("Error: IsRetryError returned wrong value")
Mohamed Abukar775722c2019-06-10 16:41:57 +0300297 }
298
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200299 ok = Rmr.IsRetryError(&RMRParams{status: 10})
300 if !ok {
301 t.Errorf("Error: IsRetryError returned wrong value")
302 }
303
304 ok = Rmr.IsNoEndPointError(&RMRParams{status: 5})
305 if ok {
306 t.Errorf("Error: IsNoEndPointError returned wrong value")
307 }
308
309 ok = Rmr.IsNoEndPointError(&RMRParams{status: 2})
310 if !ok {
311 t.Errorf("Error: IsNoEndPointError returned wrong value")
312 }
313}
314
315func TestIsErrorFunctions(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300316 Logger.Info("CASE: TestIsErrorFunctions")
Mohamed Abukar791a77f2020-02-12 19:08:42 +0200317 id, ok := Rmr.GetRicMessageId("RIC_SUB_REQ")
318 if !ok || id != 12010 {
319 t.Errorf("Error: GetRicMessageId failed: id=%d", id)
320 }
321
322 name := Rmr.GetRicMessageName(12010)
323 if name != "RIC_SUB_REQ" {
324 t.Errorf("Error: GetRicMessageName failed: name=%s", name)
Mohamed Abukar775722c2019-06-10 16:41:57 +0300325 }
326}
327
Mohamed Abukared119192020-11-19 14:38:22 +0200328func TestAddConfigChangeListener(t *testing.T) {
329 Logger.Info("CASE: AddConfigChangeListener")
330 AddConfigChangeListener(func(f string) {})
331}
332
333func TestConfigAccess(t *testing.T) {
334 Logger.Info("CASE: AddConfigChangeListener")
335
336 assert.Equal(t, Config.GetString("name"), "xapp")
337 assert.Equal(t, Config.GetInt("controls.logger.level"), 3)
338 assert.Equal(t, Config.GetUint32("controls.logger.level"), uint32(3))
339 assert.Equal(t, Config.GetBool("controls.waitForSdl"), false)
340 Config.Get("controls")
341 Config.GetStringSlice("messaging.ports")
342 Config.GetStringMap("messaging.ports")
343}
344
345func TestPublishConfigChange(t *testing.T) {
346 Logger.Info("CASE: AddConfigChangeListener")
347 PublishConfigChange("testApp", "values")
348}
349
350func TestNewSubscriber(t *testing.T) {
351 Logger.Info("CASE: TestNewSubscriber")
352 assert.NotNil(t, NewSubscriber("", 0), "NewSubscriber failed")
353}
354
355func TestNewRMRClient(t *testing.T) {
356 c := map[string]interface{} {"protPort": "tcp:4560"}
357 viper.Set("rmr", c)
358 assert.NotNil(t, NewRMRClient(), "NewRMRClient failed")
359
360 params := &RMRParams{}
361 params.Mtype = 1234
362 params.SubId = -1
363 params.Payload = []byte{1, 2, 3, 4, 5, 6}
364 Rmr.SendWithRetry(params, false, 1)
365}
366
367func TestInjectRoutePrefix(t *testing.T) {
368 Logger.Info("CASE: TestInjectRoutePrefix")
369 assert.NotNil(t, Resource.InjectRoutePrefix("test", nil), "InjectRoutePrefix failed")
370}
371
372func TestInjectStatusCb(t *testing.T) {
373 Logger.Info("CASE: TestInjectStatusCb")
374
375 var f = func() bool {
376 return true
377 }
378 Resource.InjectStatusCb(f)
379}
380
381func TestSdlInterfaces(t *testing.T) {
382 Sdl.Read("myKey")
383 Sdl.MRead([]string{"myKey"})
384 Sdl.ReadAllKeys("myKey")
385 Sdl.Store("myKey", "Values")
386 Sdl.MStore("myKey", "Values")
387 Sdl.RegisterMetrics()
388
389 // Misc.
390 var NotificationCb = func(ch string, events ...string) {}
391 Sdl.Subscribe(NotificationCb, "channel1")
392 Sdl.MSubscribe(NotificationCb, "channel1", "channel2")
393 Sdl.MStoreAndPublish([]string{"channel1"}, "event", "key1", "data1")
394}
395
396func TestRnibInterfaces(t *testing.T) {
397 Rnib.GetNodeb("test-gnb")
398 Rnib.GetCellList("test-gnb")
399 Rnib.GetListGnbIds()
400 Rnib.GetListEnbIds()
401 Rnib.GetCountGnbList()
402 Rnib.GetCell("test-gnb", 0)
403 Rnib.GetCell("test-gnb", 0)
404 Rnib.GetCellById(0, "cell-1")
405
406 // Misc.
407 var NotificationCb = func(ch string, events ...string) {}
408 Rnib.Subscribe(NotificationCb, "channel1")
409 Rnib.StoreAndPublish("channel1", "event", "key1", "data1")
410}
411
412func TestLogger(t *testing.T) {
413 Logger.Error("CASE: TestNewSubscriber")
414 Logger.Warn("CASE: TestNewSubscriber")
415}
416
417func TestConfigHandler(t *testing.T) {
418 Logger.Error("CASE: TestConfigHandler")
419 req, _ := http.NewRequest("POST", "/ric/v1/cm/appname", bytes.NewBuffer([]byte{}))
420 handleFunc := http.HandlerFunc(configHandler)
421 executeRequest(req, handleFunc)
422}
423
424func TestMisc(t *testing.T) {
425 Logger.Info("CASE: TestMisc")
426
427 IsReady()
428 SetReadyCB(func(interface{}) {}, "")
429 XappReadyCb("")
430 SetShutdownCB(func() {})
431}
432
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300433func TestTeardown(t *testing.T) {
Juha Hyttinend28b8dd2020-05-27 09:21:08 +0300434 Logger.Info("CASE: TestTeardown")
Mohamed Abukared119192020-11-19 14:38:22 +0200435 Sdl.Delete([]string{"myKey"})
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300436 Sdl.Clear()
Mohamed Abukared119192020-11-19 14:38:22 +0200437 Sdl.IsReady()
438 Sdl.GetStat()
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300439}
440
441// Helper functions
Mohamed Abukared119192020-11-19 14:38:22 +0200442func executeRequest(req *http.Request, handleR http.HandlerFunc) *httptest.ResponseRecorder {
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300443 rr := httptest.NewRecorder()
Mohamed Abukared119192020-11-19 14:38:22 +0200444 if handleR != nil {
445 vars := map[string]string{"name": "myxapp"}
446 req = mux.SetURLVars(req, vars)
447 handleR.ServeHTTP(rr, req)
448 } else {
449 vars := map[string]string{"id": "1"}
450 req = mux.SetURLVars(req, vars)
451 Resource.router.ServeHTTP(rr, req)
452 }
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300453 return rr
454}
455
456func checkResponseCode(t *testing.T, expected, actual int) {
457 if expected != actual {
458 t.Errorf("Expected response code %d. Got %d\n", expected, actual)
459 }
460}
461
462func getMetrics(t *testing.T) string {
463 req, _ := http.NewRequest("GET", "/ric/v1/metrics", nil)
Mohamed Abukared119192020-11-19 14:38:22 +0200464 response := executeRequest(req, nil)
Mohamed Abukar2e78e422019-06-02 11:45:52 +0300465
466 return response.Body.String()
Mohamed Abukar3e611c62019-07-05 13:40:11 +0300467}