1 //==================================================================================
2 // Copyright (c) 2022 Samsung
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
18 //==================================================================================
32 ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts"
33 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
34 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
35 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard"
36 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/charts"
37 h "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
38 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
39 "github.com/stretchr/testify/assert"
40 "github.com/stretchr/testify/mock"
44 var successStatus *models.Status
46 func TestMain(m *testing.M) {
48 successStatus = &models.Status{
49 Status: &health.HEALTHY,
53 HealthChecker: HealthCheckerMock{},
54 Onboarder: onboard.NewOnboarder(),
55 ChartMgr: ch.NewChartmgr(),
61 func TestHealth(t *testing.T) {
62 resp := rh.GetDMSHealth()
64 case *h.GetHealthCheckOK:
65 assert.Equal(t, successStatus, resp.(*h.GetHealthCheckOK).Payload)
67 case *h.GetHealthCheckInternalServerError:
68 assert.Fail(t, "Internal Server generated: %v", resp)
71 assert.Fail(t, "Unknown type of resp : %v", resp)
75 func TestOnboard(t *testing.T) {
76 xApp := &models.Descriptor{
77 Config: "SAMPLE_CONFIGURATION",
78 Schema: "SAMPLE_SCHEMA",
81 svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82 var d map[string]interface{}
83 reqBytes, _ := ioutil.ReadAll(r.Body)
86 err := json.Unmarshal(reqBytes, &d)
88 ricdms.Logger.Debug("after unmarshal : %+v body: %+v", d, string(reqBytes))
91 assert.Fail(t, "Not able to parse the request body")
94 assert.Equal(t, xApp.Config, d["config-file.json"])
95 assert.Equal(t, xApp.Schema, d["controls-schema.json"])
96 fmt.Fprintf(w, "SAMPLE_RESPONSE")
99 svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
104 resp := rh.OnBoard(xApp)
105 assert.NotEqual(t, nil, resp)
108 func TestGetCharts(t *testing.T) {
110 svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
111 ricdms.Logger.Debug("Mock server running")
112 fmt.Fprintf(w, "SAMPLE_RESPONSE")
115 svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
120 resp := rh.GetCharts()
121 assert.NotEqual(t, nil, resp)
123 successResp := resp.(*charts.GetChartsListOK)
124 assert.Equal(t, "SAMPLE_RESPONSE", successResp.Payload)
127 type HealthCheckerMock struct {
131 func (h HealthCheckerMock) GetStatus() *models.Status {