X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fresthooks%2Fresthooks_test.go;h=40b32ac393c725400b65294b7a7813274ac299a4;hb=c1e4374fb522f55e9263dd2deca3d244e709ebdf;hp=8e2dfcc735413b235a5de45d9284adcd386755fe;hpb=d8d204f3ca9ebfd256043f6a0de526887fdcace9;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index 8e2dfcc..40b32ac 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -33,14 +33,15 @@ 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" - "github.com/stretchr/testify/mock" ) var rh *Resthook @@ -53,9 +54,10 @@ func TestMain(m *testing.M) { } ricdms.Init() rh = &Resthook{ - HealthChecker: HealthCheckerMock{}, + HealthChecker: health.NewHealthChecker(), Onboarder: onboard.NewOnboarder(), ChartMgr: ch.NewChartmgr(), + DeployMgr: deploy.NewDeploymentManager(), } code := m.Run() os.Exit(code) @@ -75,6 +77,54 @@ func TestHealth(t *testing.T) { } } +func TestHealthxAppFail(t *testing.T) { + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(501) + })) + + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.GetxAppHealth("test", "test") + switch resp.(type) { + case *h.GetHealthCheckOK: + assert.Fail(t, "Health check should not be okay: %v", resp) + + case *h.GetHealthCheckInternalServerError: + break + + default: + assert.Fail(t, "Unknown type of resp : %v", resp) + } +} + +func TestHealthxApp(t *testing.T) { + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + })) + + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.GetxAppHealth("test", "test") + switch resp.(type) { + case *h.GetHealthCheckOK: + assert.Equal(t, successStatus, resp.(*h.GetHealthCheckOK).Payload) + + case *h.GetHealthCheckInternalServerError: + assert.Fail(t, "Internal Server generated: %v", resp) + + default: + assert.Fail(t, "Unknown type of resp : %v", resp) + } +} + func TestOnboard(t *testing.T) { xApp := &models.Descriptor{ Config: "SAMPLE_CONFIGURATION", @@ -123,8 +173,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) { @@ -201,10 +252,17 @@ func TestGetChartsByNameAndVersion(t *testing.T) { assert.IsType(t, &charts.GetChartsFetcherOK{}, resp, "response did not match type") } -type HealthCheckerMock struct { - mock.Mock +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) + } + } -func (h HealthCheckerMock) GetStatus() *models.Status { - return successStatus +func TestUninstallxApp(t *testing.T) { + response := rh.UninstallChart("test", "test", "test") + if _, ok := response.(*d.DeleteDeployInternalServerError); !ok { + assert.Fail(t, "response type did not match actual: %T", response) + } }