summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/handler.go
diff options
context:
space:
mode:
authorVictor Morales <victor.morales@intel.com>2018-10-23 11:54:58 -0700
committerVictor Morales <victor.morales@intel.com>2018-11-13 16:20:57 -0800
commitcc05d4af8f082d8174bde5c43fc45b1acc61339f (patch)
treee5614b80fd1f4762c195eb26f639f7963eb2bb5f /src/k8splugin/api/handler.go
parent7d2d48d3d0b35de0acd03c6e8a1261efd736edc3 (diff)
Create UTs to cover DB calls
This change pretends to increase the code coverage creating Unit Tests for the interactions with the Databases. Change-Id: I3b78ebe8ddb131e3c06bcee0065ad5eabeed5677 Signed-off-by: Victor Morales <victor.morales@intel.com> Issue-ID: MULTICLOUD-301
Diffstat (limited to 'src/k8splugin/api/handler.go')
-rw-r--r--src/k8splugin/api/handler.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/k8splugin/api/handler.go b/src/k8splugin/api/handler.go
index b4828b76..53fa2317 100644
--- a/src/k8splugin/api/handler.go
+++ b/src/k8splugin/api/handler.go
@@ -127,7 +127,7 @@ func CreateHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- err = db.DBconn.CreateEntry(internalVNFID, serializedResourceNameMap)
+ err = db.DBconn.Create(internalVNFID, serializedResourceNameMap)
if err != nil {
werr := pkgerrors.Wrap(err, "Create VNF deployment DB error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
@@ -156,8 +156,8 @@ func ListHandler(w http.ResponseWriter, r *http.Request) {
internalVNFIDs, err := db.DBconn.ReadAll(prefix)
if err != nil {
- werr := pkgerrors.Wrap(err, "Get VNF list error")
- http.Error(w, werr.Error(), http.StatusInternalServerError)
+ http.Error(w, pkgerrors.Wrap(err, "Get VNF list error").Error(),
+ http.StatusInternalServerError)
return
}
@@ -202,24 +202,15 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
// cloud1-default-uuid
internalVNFID := cloudRegionID + "-" + namespace + "-" + externalVNFID
- // (TODO): Read kubeconfig for specific Cloud Region from local file system
- // if present or download it from AAI
- // err := DownloadKubeConfigFromAAI(resource.CloudRegionID, os.Getenv("KUBE_CONFIG_DIR")
- kubeclient, err := GetVNFClient(os.Getenv("KUBE_CONFIG_DIR") + "/" + cloudRegionID)
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
-
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- serializedResourceNameMap, found, err := db.DBconn.ReadEntry(internalVNFID)
+ serializedResourceNameMap, err := db.DBconn.Read(internalVNFID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- if found == false {
+ if serializedResourceNameMap == "" {
w.WriteHeader(http.StatusNotFound)
return
}
@@ -233,11 +224,19 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
deserializedResourceNameMap := make(map[string][]string)
err = db.DeSerialize(serializedResourceNameMap, &deserializedResourceNameMap)
if err != nil {
- werr := pkgerrors.Wrap(err, "Delete VNF error")
+ werr := pkgerrors.Wrap(err, "Unmarshal VNF error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
return
}
+ // (TODO): Read kubeconfig for specific Cloud Region from local file system
+ // if present or download it from AAI
+ // err := DownloadKubeConfigFromAAI(resource.CloudRegionID, os.Getenv("KUBE_CONFIG_DIR")
+ kubeclient, err := GetVNFClient(os.Getenv("KUBE_CONFIG_DIR") + "/" + cloudRegionID)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
err = csar.DestroyVNF(deserializedResourceNameMap, namespace, &kubeclient)
if err != nil {
werr := pkgerrors.Wrap(err, "Delete VNF error")
@@ -245,9 +244,9 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
return
}
- err = db.DBconn.DeleteEntry(internalVNFID)
+ err = db.DBconn.Delete(internalVNFID)
if err != nil {
- werr := pkgerrors.Wrap(err, "Delete VNF error")
+ werr := pkgerrors.Wrap(err, "Delete VNF db record error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
return
}
@@ -338,13 +337,13 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
// key: cloud1-default-uuid
// value: "{"deployment":<>,"service":<>}"
- serializedResourceNameMap, found, err := db.DBconn.ReadEntry(internalVNFID)
+ serializedResourceNameMap, err := db.DBconn.Read(internalVNFID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- if found == false {
+ if serializedResourceNameMap == "" {
w.WriteHeader(http.StatusNotFound)
return
}
@@ -358,7 +357,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
deserializedResourceNameMap := make(map[string][]string)
err = db.DeSerialize(serializedResourceNameMap, &deserializedResourceNameMap)
if err != nil {
- werr := pkgerrors.Wrap(err, "Get VNF error")
+ werr := pkgerrors.Wrap(err, "Unmarshal VNF error")
http.Error(w, werr.Error(), http.StatusInternalServerError)
return
}