From: elinuxhenrik Date: Fri, 19 Nov 2021 07:25:22 +0000 (+0100) Subject: Correct unit tests for DMaaP Mediator Producer X-Git-Tag: 1.2.0~39 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F86%2F7086%2F1;p=nonrtric.git Correct unit tests for DMaaP Mediator Producer Issue-ID: NONRTRIC-639 Signed-off-by: elinuxhenrik Change-Id: I1672d546b2b414f87459c6c7895cb6866df4db88 --- diff --git a/dmaap-mediator-producer/internal/jobs/jobs_test.go b/dmaap-mediator-producer/internal/jobs/jobs_test.go index e48e68d1..552b5fa1 100644 --- a/dmaap-mediator-producer/internal/jobs/jobs_test.go +++ b/dmaap-mediator-producer/internal/jobs/jobs_test.go @@ -177,7 +177,7 @@ func TestAddJobToJobsManager_shouldStartPollAndDistributeMessages(t *testing.T) distributeClientMock := NewTestClient(func(req *http.Request) *http.Response { if req.URL.String() == "http://consumerHost/target" { assertions.Equal(req.Method, "POST") - assertions.Equal(messages, getBodyAsString(req)) + assertions.Equal(messages, getBodyAsString(req, t)) assertions.Equal("application/json", req.Header.Get("Content-Type")) wg.Done() return &http.Response{ @@ -208,7 +208,8 @@ func TestAddJobToJobsManager_shouldStartPollAndDistributeMessages(t *testing.T) } wg.Add(1) // Wait till the distribution has happened - jobsManager.AddJobFromRESTCall(jobInfo) + err := jobsManager.AddJobFromRESTCall(jobInfo) + assertions.Nil(err) if waitTimeout(&wg, 2*time.Second) { t.Error("Not all calls to server were made") @@ -287,8 +288,10 @@ func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool { } } -func getBodyAsString(req *http.Request) string { +func getBodyAsString(req *http.Request, t *testing.T) string { buf := new(bytes.Buffer) - buf.ReadFrom(req.Body) + if _, err := buf.ReadFrom(req.Body); err != nil { + t.Fail() + } return buf.String() } diff --git a/dmaap-mediator-producer/stub/consumer/consumerstub.go b/dmaap-mediator-producer/stub/consumer/consumerstub.go index 03e67c02..5cbcaeab 100644 --- a/dmaap-mediator-producer/stub/consumer/consumerstub.go +++ b/dmaap-mediator-producer/stub/consumer/consumerstub.go @@ -44,7 +44,7 @@ func main() { registerJob(*port) fmt.Print("Starting consumer on port: ", *port) - http.ListenAndServe(fmt.Sprintf(":%v", *port), nil) + fmt.Println(http.ListenAndServe(fmt.Sprintf(":%v", *port), nil)) } func registerJob(port int) { diff --git a/dmaap-mediator-producer/stub/dmaap/mrstub.go b/dmaap-mediator-producer/stub/dmaap/mrstub.go index 82ae08d5..36ffa396 100644 --- a/dmaap-mediator-producer/stub/dmaap/mrstub.go +++ b/dmaap-mediator-producer/stub/dmaap/mrstub.go @@ -57,7 +57,7 @@ func main() { http.HandleFunc("/events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/STD_Fault_Messages", handleData) fmt.Print("Starting mr on port: ", *port) - http.ListenAndServeTLS(fmt.Sprintf(":%v", *port), "../../security/producer.crt", "../../security/producer.key", nil) + fmt.Println(http.ListenAndServeTLS(fmt.Sprintf(":%v", *port), "../../security/producer.crt", "../../security/producer.key", nil)) }