aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/k8splugin/api/handler_test.go62
-rw-r--r--src/k8splugin/db/testing.go16
-rw-r--r--src/k8splugin/rb/definition_test.go82
-rw-r--r--src/k8splugin/rb/profile_test.go94
4 files changed, 151 insertions, 103 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("{}"),
+ },
},
},
},
diff --git a/src/k8splugin/db/testing.go b/src/k8splugin/db/testing.go
index 4b7e6078..003399af 100644
--- a/src/k8splugin/db/testing.go
+++ b/src/k8splugin/db/testing.go
@@ -25,7 +25,7 @@ import (
//interface even if we are not implementing all the methods in it
type MockDB struct {
Store
- Items map[string][]byte
+ Items map[string]map[string][]byte
Err error
}
@@ -49,7 +49,7 @@ func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
for k, v := range m.Items {
if k == key {
- return v, nil
+ return v[tag], nil
}
}
@@ -65,5 +65,15 @@ func (m *MockDB) ReadAll(table, tag string) (map[string][]byte, error) {
return nil, m.Err
}
- return m.Items, nil
+ ret := make(map[string][]byte)
+
+ for k, v := range m.Items {
+ for k1, v1 := range v {
+ if k1 == tag {
+ ret[k] = v1
+ }
+ }
+ }
+
+ return ret, nil
}
diff --git a/src/k8splugin/rb/definition_test.go b/src/k8splugin/rb/definition_test.go
index b3603136..f1ec18ee 100644
--- a/src/k8splugin/rb/definition_test.go
+++ b/src/k8splugin/rb/definition_test.go
@@ -110,17 +110,21 @@ func TestListDefinition(t *testing.T) {
},
expectedError: "",
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"service-type\":\"firewall\"}"),
- "123e4567-e89b-12d3-a456-426655441111": []byte(
- "{\"name\":\"testresourcebundle2\"," +
- "\"description\":\"testresourcebundle2\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
- "\"service-type\":\"dns\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"description\":\"testresourcebundle\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"service-type\":\"firewall\"}"),
+ },
+ "123e4567-e89b-12d3-a456-426655441111": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle2\"," +
+ "\"description\":\"testresourcebundle2\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
+ "\"service-type\":\"dns\"}"),
+ },
},
},
},
@@ -186,12 +190,14 @@ func TestGetDefinition(t *testing.T) {
},
expectedError: "",
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"service-type\":\"firewall\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"description\":\"testresourcebundle\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"service-type\":\"firewall\"}"),
+ },
},
},
},
@@ -298,12 +304,14 @@ func TestUploadDefinition(t *testing.T) {
0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"service-type\":\"firewall\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"description\":\"testresourcebundle\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"service-type\":\"firewall\"}"),
+ },
},
},
},
@@ -333,12 +341,14 @@ func TestUploadDefinition(t *testing.T) {
0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655441111": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
- "\"service-type\":\"firewall\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655441111": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"description\":\"testresourcebundle\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
+ "\"service-type\":\"firewall\"}"),
+ },
},
},
},
@@ -351,12 +361,14 @@ func TestUploadDefinition(t *testing.T) {
0x00, 0xff, 0xf2, 0x48, 0xcd,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"description\":\"testresourcebundle\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"service-type\":\"firewall\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"description\":\"testresourcebundle\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"service-type\":\"firewall\"}"),
+ },
},
},
},
diff --git a/src/k8splugin/rb/profile_test.go b/src/k8splugin/rb/profile_test.go
index 26b9747c..2540d3ca 100644
--- a/src/k8splugin/rb/profile_test.go
+++ b/src/k8splugin/rb/profile_test.go
@@ -54,12 +54,14 @@ func TestCreateProfile(t *testing.T) {
},
expectedError: "",
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "abcde123-e89b-8888-a456-986655447236": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "abcde123-e89b-8888-a456-986655447236": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},
@@ -115,13 +117,15 @@ func TestListProfiles(t *testing.T) {
},
expectedError: "",
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},
@@ -188,13 +192,15 @@ func TestGetProfile(t *testing.T) {
},
expectedError: "",
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},
@@ -301,13 +307,15 @@ func TestUploadProfile(t *testing.T) {
0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},
@@ -337,13 +345,15 @@ func TestUploadProfile(t *testing.T) {
0x4a, 0xf9, 0x00, 0x28, 0x00, 0x00,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655441111": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
- "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655441111": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655441111\"," +
+ "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},
@@ -356,13 +366,15 @@ func TestUploadProfile(t *testing.T) {
0x00, 0xff, 0xf2, 0x48, 0xcd,
},
mockdb: &db.MockDB{
- Items: map[string][]byte{
- "123e4567-e89b-12d3-a456-426655440000": []byte(
- "{\"name\":\"testresourcebundle\"," +
- "\"namespace\":\"default\"," +
- "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
- "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
- "\"kubernetesversion\":\"1.12.3\"}"),
+ Items: map[string]map[string][]byte{
+ "123e4567-e89b-12d3-a456-426655440000": {
+ "metadata": []byte(
+ "{\"name\":\"testresourcebundle\"," +
+ "\"namespace\":\"default\"," +
+ "\"uuid\":\"123e4567-e89b-12d3-a456-426655440000\"," +
+ "\"rbdid\":\"abcde123-e89b-8888-a456-986655447236\"," +
+ "\"kubernetesversion\":\"1.12.3\"}"),
+ },
},
},
},