X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fut_ctrl_submgr_test.go;h=3a0e0e4a4f5fb6da4f8609c80a7e4c6952e1847c;hb=47518ae7612cbfb1562fa1f74b9023389d8cfd61;hp=bc1435a689b09fb27aa094fd630f29af60227d2b;hpb=4abf18056b1674fb284c4d7d753c35a3ddab37e4;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go index bc1435a..3a0e0e4 100644 --- a/pkg/control/ut_ctrl_submgr_test.go +++ b/pkg/control/ut_ctrl_submgr_test.go @@ -46,6 +46,8 @@ type Counter struct { Value uint64 } +type CountersToBeAdded []Counter + var countersBeforeMap map[string]Counter var toBeAddedCountersMap map[string]Counter @@ -111,7 +113,7 @@ func PringSubscriptionQueryResult(resp models.SubscriptionList) { for _, item := range resp { fmt.Printf("item.SubscriptionID=%v\n", item.SubscriptionID) fmt.Printf("item.Meid=%v\n", item.Meid) - fmt.Printf("item.Endpoint=%v\n", item.Endpoint) + fmt.Printf("item.ClientEndpoint=%v\n", item.ClientEndpoint) } } @@ -258,14 +260,15 @@ func (mc *testingSubmgrControl) GetMetrics(t *testing.T) (string, error) { return string(respBody[:]), nil } -func (mc *testingSubmgrControl) SetTimesCounterWillBeAdded(counterName string, addedValue uint64) { +func (mc *testingSubmgrControl) CounterValuesToBeVeriefied(t *testing.T, countersToBeAdded CountersToBeAdded) { + if len(toBeAddedCountersMap) == 0 { toBeAddedCountersMap = make(map[string]Counter) } - counter := Counter{} - counter.Name = counterName - counter.Value = addedValue - toBeAddedCountersMap[counterName] = counter + for _, counter := range countersToBeAdded { + toBeAddedCountersMap[counter.Name] = counter + } + mc.GetCounterValuesBefore(t) } func (mc *testingSubmgrControl) GetCounterValuesBefore(t *testing.T) { @@ -329,3 +332,68 @@ func (mc *testingSubmgrControl) GetCurrentCounterValues(t *testing.T, chekedCoun } return retCounterMap } + +func (mc *testingSubmgrControl) sendGetRequest(t *testing.T, addr string, path string) { + + mc.TestLog(t, "GET http://"+addr+"%v", path) + req, err := http.NewRequest("GET", "http://"+addr+path, nil) + if err != nil { + mc.TestError(t, "Error reading request. %v", err) + return + } + req.Header.Set("Cache-Control", "no-cache") + client := &http.Client{Timeout: time.Second * 2} + resp, err := client.Do(req) + if err != nil { + mc.TestError(t, "Error reading response. %v", err) + return + } + defer resp.Body.Close() + + mc.TestLog(t, "Response status: %v", resp.Status) + mc.TestLog(t, "Response Headers: %v", resp.Header) + if !strings.Contains(resp.Status, "200 OK") { + mc.TestError(t, "Wrong response status") + return + } + + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + mc.TestError(t, "Error reading body. %v", err) + return + } + mc.TestLog(t, "%s", respBody) + return +} + +func (mc *testingSubmgrControl) sendPostRequest(t *testing.T, addr string, path string) { + + mc.TestLog(t, "POST http://"+addr+"%v", path) + req, err := http.NewRequest("POST", "http://"+addr+path, nil) + if err != nil { + mc.TestError(t, "Error reading request. %v", err) + return + } + client := &http.Client{Timeout: time.Second * 2} + resp, err := client.Do(req) + if err != nil { + mc.TestError(t, "Error reading response. %v", err) + return + } + defer resp.Body.Close() + + mc.TestLog(t, "Response status: %v", resp.Status) + mc.TestLog(t, "Response Headers: %v", resp.Header) + if !strings.Contains(resp.Status, "200 OK") { + mc.TestError(t, "Wrong response status") + return + } + + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + mc.TestError(t, "Error reading body. %v", err) + return + } + mc.TestLog(t, "%s", respBody) + return +}