aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/module/project_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/orchestrator/pkg/module/project_test.go')
-rw-r--r--src/orchestrator/pkg/module/project_test.go107
1 files changed, 106 insertions, 1 deletions
diff --git a/src/orchestrator/pkg/module/project_test.go b/src/orchestrator/pkg/module/project_test.go
index f6856f86..947478b4 100644
--- a/src/orchestrator/pkg/module/project_test.go
+++ b/src/orchestrator/pkg/module/project_test.go
@@ -62,13 +62,39 @@ func TestCreateProject(t *testing.T) {
Err: pkgerrors.New("Error Creating Project"),
},
},
+ {
+ label: "Create Existing Project",
+ inp: Project{
+ MetaData: ProjectMetaData{
+ Name: "testProject",
+ Description: "A sample Project used for unit testing",
+ UserData1: "data1",
+ UserData2: "data2",
+ },
+ },
+ expectedError: "Project already exists",
+ mockdb: &db.MockDB{
+ Items: map[string]map[string][]byte{
+ ProjectKey{ProjectName: "testProject"}.String(): {
+ "projectmetadata": []byte(
+ "{" +
+ "\"metadata\" : {" +
+ "\"Name\":\"testProject\"," +
+ "\"Description\":\"Test project for unit testing\"," +
+ "\"UserData1\":\"userData1\"," +
+ "\"UserData2\":\"userData2\"}" +
+ "}"),
+ },
+ },
+ },
+ },
}
for _, testCase := range testCases {
t.Run(testCase.label, func(t *testing.T) {
db.DBconn = testCase.mockdb
impl := NewProjectClient()
- got, err := impl.CreateProject(testCase.inp)
+ got, err := impl.CreateProject(testCase.inp, false)
if err != nil {
if testCase.expectedError == "" {
t.Fatalf("Create returned an unexpected error %s", err)
@@ -86,6 +112,85 @@ func TestCreateProject(t *testing.T) {
}
}
+func TestUpdateProject(t *testing.T) {
+ testCases := []struct {
+ label string
+ inp Project
+ expectedError string
+ mockdb *db.MockDB
+ expected Project
+ }{
+ {
+ label: "Update Project",
+ inp: Project{
+ MetaData: ProjectMetaData{
+ Name: "testProject",
+ Description: "Test project for unit testing",
+ UserData1: "update userData1",
+ UserData2: "update userData2",
+ },
+ },
+ expected: Project{
+ MetaData: ProjectMetaData{
+ Name: "testProject",
+ Description: "Test project for unit testing",
+ UserData1: "update userData1",
+ UserData2: "update userData2",
+ },
+ },
+ expectedError: "",
+ mockdb: &db.MockDB{
+ Items: map[string]map[string][]byte{
+ ProjectKey{ProjectName: "testProject"}.String(): {
+ "projectmetadata": []byte(
+ "{" +
+ "\"metadata\" : {" +
+ "\"Name\":\"testProject\"," +
+ "\"Description\":\"Test project for unit testing\"," +
+ "\"UserData1\":\"userData1\"," +
+ "\"UserData2\":\"userData2\"}" +
+ "}"),
+ },
+ },
+ },
+ },
+ {
+ label: "Failed Update Project",
+ inp: Project{
+ MetaData: ProjectMetaData{
+ Name: "unknownProject",
+ Description: "Unknown project for unit testing",
+ },
+ },
+ expectedError: "Creating DB Entry",
+ mockdb: &db.MockDB{
+ Err: pkgerrors.New("Error Updating Project"),
+ },
+ },
+ }
+
+ for _, testCase := range testCases {
+ t.Run(testCase.label, func(t *testing.T) {
+ db.DBconn = testCase.mockdb
+ impl := NewProjectClient()
+ got, err := impl.CreateProject(testCase.inp, true)
+ if err != nil {
+ if testCase.expectedError == "" {
+ t.Fatalf("Update returned an unexpected error %s", err)
+ }
+ if strings.Contains(err.Error(), testCase.expectedError) == false {
+ t.Fatalf("Update returned an unexpected error %s", err)
+ }
+ } else {
+ if reflect.DeepEqual(testCase.expected, got) == false {
+ t.Errorf("Update returned unexpected body: got %v;"+
+ " expected %v", got, testCase.expected)
+ }
+ }
+ })
+ }
+}
+
func TestGetProject(t *testing.T) {
testCases := []struct {