X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=pkg%2Fresthooks%2Fresthooks_test.go;h=40b32ac393c725400b65294b7a7813274ac299a4;hb=c1e4374fb522f55e9263dd2deca3d244e709ebdf;hp=39ff3f398cb8dbd5193f9e06b1cc09943438d108;hpb=f95c1d3a137db6a4dd4ff7d8c3a8f5a2a7a55c2f;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index 39ff3f3..40b32ac 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -42,7 +42,6 @@ import ( 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 @@ -55,7 +54,7 @@ func TestMain(m *testing.M) { } ricdms.Init() rh = &Resthook{ - HealthChecker: HealthCheckerMock{}, + HealthChecker: health.NewHealthChecker(), Onboarder: onboard.NewOnboarder(), ChartMgr: ch.NewChartmgr(), DeployMgr: deploy.NewDeploymentManager(), @@ -78,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", @@ -126,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) { @@ -212,10 +260,9 @@ func TestDownloadAndInstall(t *testing.T) { } -type HealthCheckerMock struct { - mock.Mock -} - -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) + } }