X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fresthooks%2Fresthooks_test.go;h=991fbec309239ac9826093ccc3cb0d15df59cdf4;hb=d6fcfc287d573d94e54a8116a0fc414fe5349a1a;hp=c8deeb279e29194288790563241cef544a909251;hpb=e3ac46a8c1e74aa6fea57bb7d92e763bd4bd6b7c;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index c8deeb2..991fbec 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -33,10 +33,12 @@ import ( "testing" ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/deploy" "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" + d "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/deploy" 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" @@ -56,6 +58,7 @@ func TestMain(m *testing.M) { HealthChecker: HealthCheckerMock{}, Onboarder: onboard.NewOnboarder(), ChartMgr: ch.NewChartmgr(), + DeployMgr: deploy.NewDeploymentManager(), } code := m.Run() os.Exit(code) @@ -123,8 +126,9 @@ func TestGetCharts(t *testing.T) { resp := rh.GetCharts() assert.NotEqual(t, nil, resp) - successResp := resp.(*charts.GetChartsListOK) - assert.Equal(t, "SAMPLE_RESPONSE", successResp.Payload) + if _, ok := resp.(*charts.GetChartsListOK); !ok { + assert.Fail(t, "response type did not match : %t", resp) + } } func TestDownloadChart(t *testing.T) { @@ -173,6 +177,42 @@ func TestGetChartsByName(t *testing.T) { assert.IsType(t, &charts.GetChartOK{}, resp, "response did not match type") } +func TestGetChartsByNameAndVersion(t *testing.T) { + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ricdms.Logger.Debug("request received by mock to get chart by name and version") + path, _ := filepath.Abs("./mocks/resp-get-charts-by-name-and-ver.json") + file, err := os.Open(path) + + if err != nil { + ricdms.Logger.Error("error in reading file: %v", err) + } + + jsonData, err := io.ReadAll(file) + if err != nil { + ricdms.Logger.Error("Error in rading file: %v", err) + } + w.Write(jsonData) + })) + + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.GetChartByNameAndVersion("Test", "1.0.0") + ricdms.Logger.Debug("resp data: %s", resp.(*charts.GetChartsFetcherOK).Payload) + assert.IsType(t, &charts.GetChartsFetcherOK{}, resp, "response did not match type") +} + +func TestDownloadAndInstall(t *testing.T) { + response := rh.DownloadAndInstallChart("sample app", "1.0.0", "test") + if _, ok := response.(*d.PostDeployInternalServerError); !ok { + assert.Fail(t, "response type did not match (actual) %T", response) + } + +} + type HealthCheckerMock struct { mock.Mock }