aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/vnfd
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/vnfd')
-rw-r--r--src/k8splugin/vnfd/vnfd.go12
-rw-r--r--src/k8splugin/vnfd/vnfd_test.go71
2 files changed, 20 insertions, 63 deletions
diff --git a/src/k8splugin/vnfd/vnfd.go b/src/k8splugin/vnfd/vnfd.go
index 322b2d78..0fb81dbd 100644
--- a/src/k8splugin/vnfd/vnfd.go
+++ b/src/k8splugin/vnfd/vnfd.go
@@ -67,7 +67,7 @@ func (v *VNFDefinitionClient) Create(vnfd VNFDefinition) (VNFDefinition, error)
return VNFDefinition{}, pkgerrors.Wrap(err, "Serialize VNF Definition")
}
- err = db.DBconn.CreateEntry(key, serData)
+ err = db.DBconn.Create(key, serData)
if err != nil {
return VNFDefinition{}, pkgerrors.Wrap(err, "Creating DB Entry")
}
@@ -85,12 +85,12 @@ func (v *VNFDefinitionClient) List() ([]VNFDefinition, error) {
var retData []VNFDefinition
for _, key := range strArray {
- value, ok, err := db.DBconn.ReadEntry(key)
+ value, err := db.DBconn.Read(key)
if err != nil {
log.Printf("Error Reading Key: %s", key)
continue
}
- if ok {
+ if value != "" {
vnfd := VNFDefinition{}
err = db.DeSerialize(value, &vnfd)
if err != nil {
@@ -106,12 +106,12 @@ func (v *VNFDefinitionClient) List() ([]VNFDefinition, error) {
// Get returns the VNF Definition for corresponding ID
func (v *VNFDefinitionClient) Get(vnfID string) (VNFDefinition, error) {
- value, ok, err := db.DBconn.ReadEntry(v.keyPrefix + vnfID)
+ value, err := db.DBconn.Read(v.keyPrefix + vnfID)
if err != nil {
return VNFDefinition{}, pkgerrors.Wrap(err, "Get VNF Definitions")
}
- if ok {
+ if value != "" {
vnfd := VNFDefinition{}
err = db.DeSerialize(value, &vnfd)
if err != nil {
@@ -125,7 +125,7 @@ func (v *VNFDefinitionClient) Get(vnfID string) (VNFDefinition, error) {
// Delete deletes the VNF Definition from database
func (v *VNFDefinitionClient) Delete(vnfID string) error {
- err := db.DBconn.DeleteEntry(v.keyPrefix + vnfID)
+ err := db.DBconn.Delete(v.keyPrefix + vnfID)
if err != nil {
return pkgerrors.Wrap(err, "Delete VNF Definitions")
}
diff --git a/src/k8splugin/vnfd/vnfd_test.go b/src/k8splugin/vnfd/vnfd_test.go
index 54ab5f49..3230d3ef 100644
--- a/src/k8splugin/vnfd/vnfd_test.go
+++ b/src/k8splugin/vnfd/vnfd_test.go
@@ -1,3 +1,5 @@
+// +build unit
+
/*
* Copyright 2018 Intel Corporation, Inc
*
@@ -26,57 +28,12 @@ import (
pkgerrors "github.com/pkg/errors"
)
-//Creating an embedded interface via anonymous variable
-//This allows us to make mockDB satisfy the DatabaseConnection
-//interface even if we are not implementing all the methods in it
-type mockDB struct {
- db.DatabaseConnection
- Items api.KVPairs
- Err error
-}
-
-func (m *mockDB) CreateEntry(key string, value string) error {
- return m.Err
-}
-
-func (m *mockDB) ReadEntry(key string) (string, bool, error) {
- if m.Err != nil {
- return "", false, m.Err
- }
-
- for _, kvpair := range m.Items {
- if kvpair.Key == key {
- return string(kvpair.Value), true, nil
- }
- }
-
- return "", false, nil
-}
-
-func (m *mockDB) DeleteEntry(key string) error {
- return m.Err
-}
-
-func (m *mockDB) ReadAll(prefix string) ([]string, error) {
- if m.Err != nil {
- return []string{}, m.Err
- }
-
- var res []string
-
- for _, keypair := range m.Items {
- res = append(res, keypair.Key)
- }
-
- return res, nil
-}
-
func TestCreate(t *testing.T) {
testCases := []struct {
label string
inp VNFDefinition
expectedError string
- mockdb *mockDB
+ mockdb *db.MockDB
expected VNFDefinition
}{
{
@@ -94,12 +51,12 @@ func TestCreate(t *testing.T) {
ServiceType: "firewall",
},
expectedError: "",
- mockdb: &mockDB{},
+ mockdb: &db.MockDB{},
},
{
label: "Failed Create VNF Definition",
expectedError: "Error Creating Definition",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Err: pkgerrors.New("Error Creating Definition"),
},
},
@@ -132,7 +89,7 @@ func TestList(t *testing.T) {
testCases := []struct {
label string
expectedError string
- mockdb *mockDB
+ mockdb *db.MockDB
expected []VNFDefinition
}{
{
@@ -152,7 +109,7 @@ func TestList(t *testing.T) {
},
},
expectedError: "",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Items: api.KVPairs{
&api.KVPair{
Key: "vnfd/123e4567-e89b-12d3-a456-426655440000",
@@ -174,7 +131,7 @@ func TestList(t *testing.T) {
{
label: "List Error",
expectedError: "DB Error",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Err: pkgerrors.New("DB Error"),
},
},
@@ -207,7 +164,7 @@ func TestGet(t *testing.T) {
testCases := []struct {
label string
expectedError string
- mockdb *mockDB
+ mockdb *db.MockDB
inp string
expected VNFDefinition
}{
@@ -221,7 +178,7 @@ func TestGet(t *testing.T) {
ServiceType: "firewall",
},
expectedError: "",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Items: api.KVPairs{
&api.KVPair{
Key: "vnfd/123e4567-e89b-12d3-a456-426655440000",
@@ -236,7 +193,7 @@ func TestGet(t *testing.T) {
{
label: "Get Error",
expectedError: "DB Error",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Err: pkgerrors.New("DB Error"),
},
},
@@ -270,18 +227,18 @@ func TestDelete(t *testing.T) {
label string
inp string
expectedError string
- mockdb *mockDB
+ mockdb *db.MockDB
expected []VNFDefinition
}{
{
label: "Delete VNF Definition",
inp: "123e4567-e89b-12d3-a456-426655440000",
- mockdb: &mockDB{},
+ mockdb: &db.MockDB{},
},
{
label: "Delete Error",
expectedError: "DB Error",
- mockdb: &mockDB{
+ mockdb: &db.MockDB{
Err: pkgerrors.New("DB Error"),
},
},