From 10b17da590fc43622c6080815f65fbbb2721b640 Mon Sep 17 00:00:00 2001 From: enyinna1234 Date: Fri, 14 Feb 2020 08:41:49 -0800 Subject: Add Distributed Cloud Manager This handles RESTful API CRUD operations for logical clouds, CLuster, User Permissions, Quota, and Key Value pairs. See: https://wiki.onap.org/x/tAiVB Issue-ID: MULTICLOUD-996 Signed-off-by: Enyinna Ochulor Change-Id: I654a304cd682f762c02cfd92b4483d1edea63fca --- src/dcm/pkg/module/userpermissions_test.go | 110 +++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/dcm/pkg/module/userpermissions_test.go (limited to 'src/dcm/pkg/module/userpermissions_test.go') diff --git a/src/dcm/pkg/module/userpermissions_test.go b/src/dcm/pkg/module/userpermissions_test.go new file mode 100644 index 00000000..f134aa0f --- /dev/null +++ b/src/dcm/pkg/module/userpermissions_test.go @@ -0,0 +1,110 @@ +package module + +import ( + "testing" + + "github.com/pkg/errors" + +) + + +func TestCreateUserPerm(t *testing.T) { + + up := UserPermission { + UserPermissionName: "test_user_perm", + } + data1 := [][]byte{} + + // data2 := []byte("abc") + + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", up).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + // myMocks.On("DBUnmarshal", data2).Return(nil) + + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.CreateUserPerm("test_project", "test_asdf", up) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetUserPerm(t *testing.T) { + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.GetUserPerm("test_project", "test_asdf", "test_user_perm") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteUserPerm(t *testing.T) { + + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + err := upClient.DeleteUserPerm("test_project", "test_asdf", "test_user_perm") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateUserPerm(t *testing.T) { + key := UserPermissionKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + UserPermissionName: "test_user_perm", + } + up := UserPermission{ + UserPermissionName: "test_user_perm", + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", up).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + upClient := UserPermissionClient{"test_dcm", "test_meta", myMocks} + _, err := upClient.UpdateUserPerm("test_project", "test_asdf", "test_user_perm", up) + if err != nil { + t.Errorf("Some error occured!") + } +} -- cgit 1.2.3-korg