aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/handler_test.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-01-23 12:09:42 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-01-23 12:09:46 -0800
commit704d7c52983cd935b48d4eb38108c758c7b6c67d (patch)
treef43035dc95795708c743a8e57d79c2a2d6876168 /src/k8splugin/api/handler_test.go
parentf26259e651ee0be263a3398d2d0ca0eb27c8995c (diff)
Add support for tags in the mockdb
Add support for tags in mockdb. Needed for supporting unit tests where a method does multiple db calls using same uuid but different tags. Eg: Download methods Issue-ID: MULTICLOUD-455 Change-Id: I4eff8eeb00eac630205e4e186981a53a573b61fa 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.go62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/k8splugin/api/handler_test.go b/src/k8splugin/api/handler_test.go
index a3aeff7a..d02b8515 100644
--- a/src/k8splugin/api/handler_test.go
+++ b/src/k8splugin/api/handler_test.go
@@ -203,8 +203,10 @@ func TestListHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedResponse: []string{"uid1"},
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "uuid1": []byte("{}"),
+ Items: map[string]map[string][]byte{
+ "uuid1": {
+ "data": []byte("{}"),
+ },
},
},
},
@@ -257,15 +259,17 @@ func TestDeleteHandler(t *testing.T) {
label: "Fail to find VNF record be deleted",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: map[string][]byte{},
+ Items: map[string]map[string][]byte{},
},
},
{
label: "Fail to unmarshal the DB record",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloudregion1-testnamespace-uuid1": []byte("{invalid format}"),
+ Items: map[string]map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": {
+ "data": []byte("{invalid format}"),
+ },
},
},
},
@@ -274,10 +278,12 @@ func TestDeleteHandler(t *testing.T) {
expectedCode: http.StatusInternalServerError,
mockGetVNFClientErr: pkgerrors.New("Get VNF client error"),
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloudregion1-testnamespace-uuid1": []byte(
- "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]}"),
+ Items: map[string]map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": {
+ "data": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
+ },
},
},
},
@@ -285,10 +291,12 @@ func TestDeleteHandler(t *testing.T) {
label: "Fail to destroy VNF",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloudregion1-testnamespace-uuid1": []byte(
- "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]}"),
+ Items: map[string]map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": {
+ "data": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
+ },
},
},
mockDeleteVNF: &mockCSAR{
@@ -299,10 +307,12 @@ func TestDeleteHandler(t *testing.T) {
label: "Succesful delete a VNF",
expectedCode: http.StatusAccepted,
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloudregion1-testnamespace-uuid1": []byte(
- "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]}"),
+ Items: map[string]map[string][]byte{
+ "cloudregion1-testnamespace-uuid1": {
+ "data": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
+ },
},
},
mockDeleteVNF: &mockCSAR{},
@@ -412,8 +422,10 @@ func TestGetHandler(t *testing.T) {
label: "Fail to unmarshal the DB record",
expectedCode: http.StatusInternalServerError,
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloud1-default-1": []byte("{invalid-format}"),
+ Items: map[string]map[string][]byte{
+ "cloud1-default-1": {
+ "data": []byte("{invalid-format}"),
+ },
},
},
},
@@ -430,11 +442,13 @@ func TestGetHandler(t *testing.T) {
},
},
mockStore: &db.MockDB{
- Items: map[string][]byte{
- "cloud1-default-1": []byte(
- "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
- "\"service\": [\"svc1\", \"svc2\"]}"),
- "cloud1-default-2": []byte("{}"),
+ Items: map[string]map[string][]byte{
+ "cloud1-default-1": {
+ "data": []byte(
+ "{\"deployment\": [\"deploy1\", \"deploy2\"]," +
+ "\"service\": [\"svc1\", \"svc2\"]}"),
+ "cloud1-default-2": []byte("{}"),
+ },
},
},
},