X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fresthooks%2Fresthooks_test.go;h=517fb1111d2729927f478c260a19c0c3a07bc6bd;hb=refs%2Fchanges%2F89%2F9189%2F2;hp=e7cbfbdadec41065c8fb5a76f79a45f9f19f9387;hpb=cd6cc6ad28c32ccce6a2833917f7408a798e45fc;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index e7cbfbd..517fb11 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -20,11 +20,20 @@ package resthooks import ( + "encoding/json" + "fmt" + "io/ioutil" + "net" + "net/http" + "net/http/httptest" "os" "testing" + ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/charts" h "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms" "github.com/stretchr/testify/assert" @@ -42,6 +51,8 @@ func TestMain(m *testing.M) { ricdms.Init() rh = &Resthook{ HealthChecker: HealthCheckerMock{}, + Onboarder: onboard.NewOnboarder(), + ChartMgr: ch.NewChartmgr(), } code := m.Run() os.Exit(code) @@ -61,6 +72,58 @@ func TestHealth(t *testing.T) { } } +func TestOnboard(t *testing.T) { + xApp := &models.Descriptor{ + Config: "SAMPLE_CONFIGURATION", + Schema: "SAMPLE_SCHEMA", + } + + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var d map[string]interface{} + reqBytes, _ := ioutil.ReadAll(r.Body) + defer r.Body.Close() + + err := json.Unmarshal(reqBytes, &d) + + ricdms.Logger.Debug("after unmarshal : %+v body: %+v", d, string(reqBytes)) + + if err != nil { + assert.Fail(t, "Not able to parse the request body") + } + + assert.Equal(t, xApp.Config, d["config-file.json"]) + assert.Equal(t, xApp.Schema, d["controls-schema.json"]) + fmt.Fprintf(w, "SAMPLE_RESPONSE") + })) + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.OnBoard(xApp) + assert.NotEqual(t, nil, resp) +} + +func TestGetCharts(t *testing.T) { + + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ricdms.Logger.Debug("Mock server running") + fmt.Fprintf(w, "SAMPLE_RESPONSE") + })) + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.GetCharts() + assert.NotEqual(t, nil, resp) + + successResp := resp.(*charts.GetChartsListOK) + assert.Equal(t, "SAMPLE_RESPONSE", successResp.Payload) +} + type HealthCheckerMock struct { mock.Mock }