From 704d7c52983cd935b48d4eb38108c758c7b6c67d Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Wed, 23 Jan 2019 12:09:42 -0800 Subject: 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 --- src/k8splugin/api/handler_test.go | 62 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) (limited to 'src/k8splugin/api') 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("{}"), + }, }, }, }, -- cgit 1.2.3-korg