X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=cmd%2Fappmgr%2Fapi_test.go;h=89e4a0867b00c8d08092e413b7ace4e5a509b86b;hb=2d70448ee0d4ea44be1bf81fab9056abb01c28f0;hp=2648dee50e5e4eb0e8d0e4bedd7b57bd4073167b;hpb=97e8d9a3254989f086d7ad02c168442832b49946;p=ric-plt%2Fappmgr.git diff --git a/cmd/appmgr/api_test.go b/cmd/appmgr/api_test.go index 2648dee..89e4a08 100755 --- a/cmd/appmgr/api_test.go +++ b/cmd/appmgr/api_test.go @@ -41,6 +41,9 @@ var helmError error type MockedHelmer struct { } +func (h *MockedHelmer) SetCM(cm ConfigMapper) { +} + func (sd *MockedHelmer) Initialize() { } @@ -56,7 +59,7 @@ func (h *MockedHelmer) List() (names []string, err error) { return names, helmError } -func (h *MockedHelmer) Install(m ConfigMetadata) (Xapp, error) { +func (h *MockedHelmer) Install(m XappDeploy) (Xapp, error) { return xapp, helmError } @@ -71,9 +74,10 @@ func TestMain(m *testing.M) { xapp = Xapp{} xapps = []Xapp{} + cm := MockedConfigMapper{} h := MockedHelmer{} x = XappManager{} - x.Initialize(&h) + x.Initialize(&h, &cm) // Just run on the background (for coverage) go x.Run() @@ -154,6 +158,36 @@ func TestDeleteAppRemovesGivenXapp(t *testing.T) { checkResponseCode(t, http.StatusNotFound, response.Code) } +func TestGetConfigReturnsEmpty(t *testing.T) { + req, _ := http.NewRequest("GET", "/ric/v1/config", nil) + response := executeRequest(req) + + checkResponseCode(t, http.StatusOK, response.Code) +} + +func TestCreateConfigFailsWithMethodNotAllowed(t *testing.T) { + req, _ := http.NewRequest("POST", "/ric/v1/config", nil) + response := executeRequest(req) + + checkResponseCode(t, http.StatusMethodNotAllowed, response.Code) +} + +func TestCreateConfigOk(t *testing.T) { + payload := []byte(`{"name":"dummy-xapp"}`) + req, _ := http.NewRequest("POST", "/ric/v1/config", bytes.NewBuffer(payload)) + response := executeRequest(req) + + checkResponseCode(t, http.StatusCreated, response.Code) +} + +func TestDeleteConfigOk(t *testing.T) { + payload := []byte(`{"name":"dummy-xapp"}`) + req, _ := http.NewRequest("DELETE", "/ric/v1/config", bytes.NewBuffer(payload)) + response := executeRequest(req) + + checkResponseCode(t, http.StatusNotFound, response.Code) +} + // Error handling func TestGetXappReturnsError(t *testing.T) { helmError = errors.New("Not found") @@ -258,13 +292,15 @@ func generateXapp(name, status, ver, iname, istatus, ip, port string) (x Xapp) { x.Status = status x.Version = ver p, _ := strconv.Atoi(port) + var msgs MessageTypes + instance := XappInstance{ Name: iname, Status: istatus, Ip: ip, Port: p, - TxMessages: []string{"RIC_E2_TERMINATION_HC_REQUEST", "RIC_E2_MANAGER_HC_REQUEST"}, - RxMessages: []string{"RIC_E2_TERMINATION_HC_RESPONSE", "RIC_E2_MANAGER_HC_RESPONSE"}, + TxMessages: msgs.TxMessages, + RxMessages: msgs.RxMessages, } x.Instances = append(x.Instances, instance)