summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/handler_test.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-12-10 13:34:16 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-12-14 14:26:26 -0800
commitd203ccf9174e450b6f5a6a9aabea95b73c9973ff (patch)
tree702034eafbd28b47f33023607ee213cf92519a99 /src/k8splugin/api/handler_test.go
parentaa56022e0fba3c358e46e8671d9a0cd36094ebaa (diff)
Migrating from consul to mongodb for backend
Migrating to mongodb from consul. The main reason being the value size limitation of 512kb in consul. See https://jira.onap.org/browse/MULTICLOUD-426 for details. This requires a little bit of hierarchy management and data management. We are no longer converting structs to json encoded strings. The underlying db supports structs without any modifications. Also, since Mongo has the concept of collections, each submodule can use its own collection for storage as needed. Definition uses a collection called rbdef right now. P10: Enabling unit tests for mongo.go. This requires the usage of aliased functions. P11: Expanded unit tests for all functions in mongo.go P12: Refactored parameter validation. Removed TestHealthCheck as we are not mocking any of the db commands right now Checking return value of read with an expected value P13: Adding back consul support. Fixing functional test Full consul implementation check and modifications is being tracked by MULTICLOUD-427 P15: Fix ReadAll unit test and corresponding code ReadAll now returns error when no objects are found Issue-ID: MULTICLOUD-426 Change-Id: I42d239b324025fc4ef4e561790aceeff794001ef Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api/handler_test.go')
-rw-r--r--src/k8splugin/api/handler_test.go101
1 files changed, 28 insertions, 73 deletions
diff --git a/src/k8splugin/api/handler_test.go b/src/k8splugin/api/handler_test.go
index 3336bbc2..a3aeff7a 100644
--- a/src/k8splugin/api/handler_test.go
+++ b/src/k8splugin/api/handler_test.go
@@ -24,7 +24,6 @@ import (
"reflect"
"testing"
- "github.com/hashicorp/consul/api"
pkgerrors "github.com/pkg/errors"
"k8s.io/client-go/kubernetes"
@@ -194,37 +193,18 @@ func TestListHandler(t *testing.T) {
},
},
{
- label: "Get result from DB non-records",
- expectedCode: http.StatusNotFound,
- mockStore: &db.MockDB{},
- },
- {
label: "Get empty list",
expectedCode: http.StatusOK,
expectedResponse: []string{""},
- mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "",
- Value: []byte("{}"),
- },
- },
- },
+ mockStore: &db.MockDB{},
},
{
label: "Succesful get a list of VNF",
expectedCode: http.StatusOK,
- expectedResponse: []string{"uid1", "uid2"},
+ expectedResponse: []string{"uid1"},
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "uuid1",
- Value: []byte("{}"),
- },
- &api.KVPair{
- Key: "uuid2",
- Value: []byte("{}"),
- },
+ Items: map[string][]byte{
+ "uuid1": []byte("{}"),
},
},
},
@@ -275,20 +255,17 @@ func TestDeleteHandler(t *testing.T) {
},
{
label: "Fail to find VNF record be deleted",
- expectedCode: http.StatusNotFound,
+ expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: api.KVPairs{},
+ Items: map[string][]byte{},
},
},
{
label: "Fail to unmarshal the DB record",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloudregion1-testnamespace-uuid1",
- Value: []byte("{invalid format}"),
- },
+ Items: map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": []byte("{invalid format}"),
},
},
},
@@ -297,14 +274,10 @@ func TestDeleteHandler(t *testing.T) {
expectedCode: http.StatusInternalServerError,
mockGetVNFClientErr: pkgerrors.New("Get VNF client error"),
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloudregion1-testnamespace-uuid1",
- Value: []byte("{" +
- "\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]" +
- "}"),
- },
+ Items: map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
},
},
},
@@ -312,14 +285,10 @@ func TestDeleteHandler(t *testing.T) {
label: "Fail to destroy VNF",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloudregion1-testnamespace-uuid1",
- Value: []byte("{" +
- "\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]" +
- "}"),
- },
+ Items: map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
},
},
mockDeleteVNF: &mockCSAR{
@@ -330,14 +299,10 @@ func TestDeleteHandler(t *testing.T) {
label: "Succesful delete a VNF",
expectedCode: http.StatusAccepted,
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloudregion1-testnamespace-uuid1",
- Value: []byte("{" +
- "\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]" +
- "}"),
- },
+ Items: map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
},
},
mockDeleteVNF: &mockCSAR{},
@@ -440,18 +405,15 @@ func TestGetHandler(t *testing.T) {
},
{
label: "Not found DB record",
- expectedCode: http.StatusNotFound,
+ expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{},
},
{
label: "Fail to unmarshal the DB record",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloud1-default-1",
- Value: []byte("{invalid-format}"),
- },
+ Items: map[string][]byte{
+ "cloud1-default-1": []byte("{invalid-format}"),
},
},
},
@@ -468,18 +430,11 @@ func TestGetHandler(t *testing.T) {
},
},
mockStore: &db.MockDB{
- Items: api.KVPairs{
- &api.KVPair{
- Key: "cloud1-default-1",
- Value: []byte("{" +
- "\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]" +
- "}"),
- },
- &api.KVPair{
- Key: "cloud1-default-2",
- Value: []byte("{}"),
- },
+ Items: map[string][]byte{
+ "cloud1-default-1": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
+ "cloud1-default-2": []byte("{}"),
},
},
},