Delete issues error code 404 when project name is invalid 34/112434/6
authorAditya Sharoff <aditya.sharoff@intel.com>
Wed, 9 Sep 2020 23:22:32 +0000 (16:22 -0700)
committerAditya Sharoff <aditya.sharoff@intel.com>
Tue, 15 Sep 2020 20:17:56 +0000 (13:17 -0700)
Issue-ID: MULTICLOUD-1147

Signed-off-by: Aditya Sharoff <aditya.sharoff@intel.com>
Change-Id: I659dfcb00b3f15bcf787ac3947f8755737b1fc39

src/orchestrator/api/projecthandler.go
src/orchestrator/api/projecthandler_test.go
src/orchestrator/scripts/start-dev.sh

index 07cd79c..e88114a 100644 (file)
@@ -167,7 +167,13 @@ func (h projectHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
        vars := mux.Vars(r)
        name := vars["project-name"]
 
-       err := h.client.DeleteProject(name)
+       _, err := h.client.GetProject(name)
+       if err != nil {
+               http.Error(w, err.Error(), http.StatusNotFound)
+               return
+       }
+
+       err = h.client.DeleteProject(name)
        if err != nil {
                http.Error(w, err.Error(), http.StatusInternalServerError)
                return
index 5e88bab..639a266 100644 (file)
@@ -323,11 +323,23 @@ func TestProjectDeleteHandler(t *testing.T) {
                        label:         "Delete Project",
                        expectedCode:  http.StatusNoContent,
                        name:          "testProject",
-                       projectClient: &mockProjectManager{},
+                       projectClient: &mockProjectManager{
+                               //Items that will be returned by the mocked Client
+                               Items: []moduleLib.Project{
+                                       {
+                                               MetaData: moduleLib.ProjectMetaData{
+                                                       Name:        "testProject",
+                                                       Description: "Test Project used for unit testing",
+                                                       UserData1:   "data1",
+                                                       UserData2:   "data2",
+                                               },
+                                       },
+                               },
+                       },
                },
                {
                        label:        "Delete Non-Exiting Project",
-                       expectedCode: http.StatusInternalServerError,
+                       expectedCode: http.StatusNotFound,
                        name:         "testProject",
                        projectClient: &mockProjectManager{
                                Err: pkgerrors.New("Internal Error"),
index ad21dc4..775b218 100755 (executable)
@@ -28,6 +28,5 @@ echo "Compiling source code"
 pushd $opath
 generate_config
 make all
-cp -r $k8s_path/src/orchestrator/json-schemas $k8s_path/src/orchestrator
 ./orchestrator
 popd