summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api/defhandler.go
diff options
context:
space:
mode:
authorVictor Morales <victor.morales@intel.com>2019-03-22 23:31:56 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-22 23:31:56 +0000
commit8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (patch)
tree51d4392b09671e7e0f4f02862401dac4f74eef16 /src/k8splugin/api/defhandler.go
parent79b27040152a7c4ce3145b15d726645d90ea79d9 (diff)
parent4cd4539c71919a322180713c225fe23edf0eb12e (diff)
Merge "Use httptest instead of http in unit tests"
Diffstat (limited to 'src/k8splugin/api/defhandler.go')
-rw-r--r--src/k8splugin/api/defhandler.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/k8splugin/api/defhandler.go b/src/k8splugin/api/defhandler.go
index 44521dd1..f72247ab 100644
--- a/src/k8splugin/api/defhandler.go
+++ b/src/k8splugin/api/defhandler.go
@@ -18,6 +18,7 @@ package api
import (
"encoding/json"
+ "io"
"io/ioutil"
"k8splugin/internal/rb"
"net/http"
@@ -37,13 +38,12 @@ type rbDefinitionHandler struct {
func (h rbDefinitionHandler) createHandler(w http.ResponseWriter, r *http.Request) {
var v rb.Definition
- if r.Body == nil {
+ err := json.NewDecoder(r.Body).Decode(&v)
+ switch {
+ case err == io.EOF:
http.Error(w, "Empty body", http.StatusBadRequest)
return
- }
-
- err := json.NewDecoder(r.Body).Decode(&v)
- if err != nil {
+ case err != nil:
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
}
@@ -74,17 +74,17 @@ func (h rbDefinitionHandler) uploadHandler(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r)
uuid := vars["rbdID"]
- if r.Body == nil {
- http.Error(w, "Empty Body", http.StatusBadRequest)
- return
- }
-
inpBytes, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, "Unable to read body", http.StatusBadRequest)
return
}
+ if len(inpBytes) == 0 {
+ http.Error(w, "Empty body", http.StatusBadRequest)
+ return
+ }
+
err = h.client.Upload(uuid, inpBytes)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)