X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fresthooks%2Fresthooks_test.go;h=c8deeb279e29194288790563241cef544a909251;hb=e3ac46a8c1e74aa6fea57bb7d92e763bd4bd6b7c;hp=517fb1111d2729927f478c260a19c0c3a07bc6bd;hpb=6e8d970e6ec582bd4473c3fbb6772906658608ca;p=ric-plt%2Fricdms.git diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go index 517fb11..c8deeb2 100644 --- a/pkg/resthooks/resthooks_test.go +++ b/pkg/resthooks/resthooks_test.go @@ -22,11 +22,14 @@ package resthooks import ( "encoding/json" "fmt" + "io" "io/ioutil" "net" "net/http" "net/http/httptest" "os" + "path/filepath" + "strings" "testing" ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts" @@ -124,6 +127,52 @@ func TestGetCharts(t *testing.T) { assert.Equal(t, "SAMPLE_RESPONSE", successResp.Payload) } +func TestDownloadChart(t *testing.T) { + svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ricdms.Logger.Debug("request received by mock to download chart") + reader := strings.NewReader("SAMPLE_RESPONSE") + data, _ := io.ReadAll(reader) + ricdms.Logger.Debug("writing : %+v", data) + w.Write(data) + })) + svr.Listener.Close() + svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer) + + svr.Start() + defer svr.Close() + + resp := rh.DownloadChart("CHART_NAME", "VERSION") + 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 }