X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fresthooks%2Fresthooks_test.go;h=c8deeb279e29194288790563241cef544a909251;hb=refs%2Fchanges%2F45%2F9245%2F1;hp=b18b1648ccb85f7b243b3bb337d12e6748b77f78;hpb=f8dc81bc7dd198da9fcb17bef2e164dc71c39e49;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index b18b164..c8deeb2 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -28,6 +28,7 @@ import ( "net/http" "net/http/httptest" "os" + "path/filepath" "strings" "testing" @@ -144,6 +145,34 @@ func TestDownloadChart(t *testing.T) { assert.IsType(t, &charts.DownloadHelmChartOK{}, resp, "response did not match type") } +func TestGetChartsByName(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") + path, _ := filepath.Abs("./mocks/resp-get-charts-by-name.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.GetChartsByName("TEST_NAME") + ricdms.Logger.Debug("resp Data: %s", resp.(*charts.GetChartOK).Payload...) + assert.IsType(t, &charts.GetChartOK{}, resp, "response did not match type") +} + type HealthCheckerMock struct { mock.Mock }