aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/api/projecthandler_test.go
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-07-28 16:28:10 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-28 16:28:10 +0000
commitdd8caf8bc7024ec0ef1bfe448b0f61428a69ba05 (patch)
tree420a1bc428bc6ee6a7434f97a6ff245b9f32896e /src/orchestrator/api/projecthandler_test.go
parentd641c3864d4ba71e127d332c4ac2082f98bba1e5 (diff)
parentb102d4ab1a47809f514213eb1f997d4f60893c9f (diff)
Merge "Adds PUT api to v2/projects"
Diffstat (limited to 'src/orchestrator/api/projecthandler_test.go')
-rw-r--r--src/orchestrator/api/projecthandler_test.go95
1 files changed, 94 insertions, 1 deletions
diff --git a/src/orchestrator/api/projecthandler_test.go b/src/orchestrator/api/projecthandler_test.go
index dae87e2b..6810099f 100644
--- a/src/orchestrator/api/projecthandler_test.go
+++ b/src/orchestrator/api/projecthandler_test.go
@@ -40,7 +40,7 @@ type mockProjectManager struct {
Err error
}
-func (m *mockProjectManager) CreateProject(inp moduleLib.Project) (moduleLib.Project, error) {
+func (m *mockProjectManager) CreateProject(inp moduleLib.Project, exists bool) (moduleLib.Project, error) {
if m.Err != nil {
return moduleLib.Project{}, m.Err
}
@@ -144,6 +144,99 @@ func TestProjectCreateHandler(t *testing.T) {
}
}
+func TestProjectUpdateHandler(t *testing.T) {
+ testCases := []struct {
+ label, name string
+ reader io.Reader
+ expected moduleLib.Project
+ expectedCode int
+ projectClient *mockProjectManager
+ }{
+ {
+ label: "Missing Project Name in Request Body",
+ name: "testProject",
+ reader: bytes.NewBuffer([]byte(`{
+ "description":"test description"
+ }`)),
+ expectedCode: http.StatusBadRequest,
+ projectClient: &mockProjectManager{},
+ },
+ {
+ label: "Missing Body Failure",
+ name: "testProject",
+ expectedCode: http.StatusBadRequest,
+ projectClient: &mockProjectManager{},
+ },
+ {
+ label: "Mismatched Name Failure",
+ name: "testProject",
+ expectedCode: http.StatusBadRequest,
+ reader: bytes.NewBuffer([]byte(`{
+ "metadata" : {
+ "name": "testProjectNameMismatch",
+ "description": "Test Project used for unit testing"
+ }
+ }`)),
+ projectClient: &mockProjectManager{},
+ },
+ {
+ label: "Update Project",
+ name: "testProject",
+ expectedCode: http.StatusOK,
+ reader: bytes.NewBuffer([]byte(`{
+ "metadata" : {
+ "name": "testProject",
+ "description": "Test Project used for unit testing"
+ }
+ }`)),
+ expected: moduleLib.Project{
+ MetaData: moduleLib.ProjectMetaData{
+ Name: "testProject",
+ Description: "Test Project used for unit testing",
+ UserData1: "update data1",
+ UserData2: "update data2",
+ },
+ },
+ 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: "update data1",
+ UserData2: "update data2",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.label, func(t *testing.T) {
+ request := httptest.NewRequest("PUT", "/v2/projects/"+testCase.name, testCase.reader)
+ resp := executeRequest(request, NewRouter(testCase.projectClient, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil))
+
+ //Check returned code
+ if resp.StatusCode != testCase.expectedCode {
+ t.Fatalf("Expected %d; Got: %d", testCase.expectedCode, resp.StatusCode)
+ }
+
+ //Check returned body only if statusOK
+ if resp.StatusCode == http.StatusOK {
+ got := moduleLib.Project{}
+ json.NewDecoder(resp.Body).Decode(&got)
+
+ if reflect.DeepEqual(testCase.expected, got) == false {
+ t.Errorf("updateHandler returned unexpected body: got %v;"+
+ " expected %v", got, testCase.expected)
+ }
+ }
+ })
+ }
+}
+
func TestProjectGetHandler(t *testing.T) {
testCases := []struct {