diff options
author | enyinna1234 <enyinna.ochulor@intel.com> | 2020-02-14 08:41:49 -0800 |
---|---|---|
committer | enyinna1234 <enyinna.ochulor@intel.com> | 2020-04-10 08:15:33 -0700 |
commit | 10b17da590fc43622c6080815f65fbbb2721b640 (patch) | |
tree | b9a8f456f97fd8ac3883bacf7835a2baaceed9a2 /src/dcm/pkg/module/keyvalue_test.go | |
parent | 335c7cca38eb804c2977e4dd9af9efa0ea7ef82b (diff) |
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 <enyinna.ochulor@intel.com>
Change-Id: I654a304cd682f762c02cfd92b4483d1edea63fca
Diffstat (limited to 'src/dcm/pkg/module/keyvalue_test.go')
-rw-r--r-- | src/dcm/pkg/module/keyvalue_test.go | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/dcm/pkg/module/keyvalue_test.go b/src/dcm/pkg/module/keyvalue_test.go new file mode 100644 index 00000000..9faceda4 --- /dev/null +++ b/src/dcm/pkg/module/keyvalue_test.go @@ -0,0 +1,115 @@ +package module
+
+import (
+ "testing"
+
+ "github.com/pkg/errors"
+
+)
+
+
+func TestCreateKVPair(t *testing.T) {
+
+ mData := KVMetaDataList{
+ KeyValueName: "test_kv_pair",
+ }
+
+ kv := KeyValue {
+ MetaData: mData,
+ }
+ data1 := [][]byte{}
+
+
+ key := KeyValueKey{
+ Project: "test_project",
+ LogicalCloudName: "test_asdf",
+ KeyValueName: "test_kv_pair",
+ }
+ 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", kv).Return(nil)
+ myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1)
+
+ kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks}
+ _, err := kvClient.CreateKVPair("test_project", "test_asdf", kv)
+ if err != nil {
+ t.Errorf("Some error occured!")
+ }
+}
+
+func TestGetKVPair(t *testing.T) {
+ key := KeyValueKey{
+ Project: "test_project",
+ LogicalCloudName: "test_asdf",
+ KeyValueName: "test_kv_pair",
+ }
+
+ 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)
+ kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks}
+ _, err := kvClient.GetKVPair("test_project", "test_asdf", "test_kv_pair")
+ if err != nil {
+ t.Errorf("Some error occured!")
+ }
+}
+
+func TestDeleteKVPair(t *testing.T) {
+
+ key := KeyValueKey{
+ Project: "test_project",
+ LogicalCloudName: "test_asdf",
+ KeyValueName: "test_kv_pair",
+ }
+
+ myMocks := new(mockValues)
+
+ myMocks.On("DBRemove", "test_dcm", key).Return(nil)
+
+ kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks}
+ err := kvClient.DeleteKVPair("test_project", "test_asdf", "test_kv_pair")
+ if err != nil {
+ t.Errorf("Some error occured!")
+ }
+
+}
+
+func TestUpdateKVPair(t *testing.T) {
+ key := KeyValueKey{
+ Project: "test_project",
+ LogicalCloudName: "test_asdf",
+ KeyValueName: "test_kv_pair",
+ }
+ mData := KVMetaDataList{
+ KeyValueName: "test_kv_pair",
+ }
+ kv := KeyValue{
+ MetaData: mData,
+ }
+ data1 := [][]byte{
+ []byte("abc"),
+ }
+ data2 := []byte("abc")
+
+ myMocks := new(mockValues)
+
+ myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", kv).Return(nil)
+ myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
+ myMocks.On("DBUnmarshal", data2).Return(nil)
+ kvClient := KeyValueClient{"test_dcm", "test_meta", myMocks}
+ _, err := kvClient.UpdateKVPair("test_project", "test_asdf", "test_kv_pair", kv)
+ if err != nil {
+ t.Errorf("Some error occured!")
+ }
+}
|