summaryrefslogtreecommitdiffstats
path: root/sms-service/src
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-03-13 12:59:37 -0700
committerGirish Havaldar <hg0071052@techmahindra.com>2018-03-15 17:00:33 +0000
commit9b16de820c0bef5643746bdeb3186714a85281f1 (patch)
tree44cfb4ed3f1f22de9bc69edd62b83d3f033cfa99 /sms-service/src
parent75dd5474ec6a2a1c4fbf513e82ba6f4ae08f85f6 (diff)
Update listsecret return to send a JSON object
Instead of sending JSONArray, retrun JSON object for consistency and client processing Issue-ID: AAF-172 Change-Id: I17d2e2c2865a817c8016987f998c87259413f306 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'sms-service/src')
-rw-r--r--sms-service/src/sms/handler/handler.go11
-rw-r--r--sms-service/src/sms/handler/handler_test.go11
2 files changed, 18 insertions, 4 deletions
diff --git a/sms-service/src/sms/handler/handler.go b/sms-service/src/sms/handler/handler.go
index 4456806..f2800fc 100644
--- a/sms-service/src/sms/handler/handler.go
+++ b/sms-service/src/sms/handler/handler.go
@@ -131,14 +131,21 @@ func (h handler) listSecretHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
domName := vars["domName"]
- sec, err := h.secretBackend.ListSecret(domName)
+ secList, err := h.secretBackend.ListSecret(domName)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- jdata, err := json.Marshal(sec)
+ // Creating an anonymous struct to store the returned list of data
+ var retStruct = struct {
+ SecretNames []string `json:"secretnames"`
+ }{
+ secList,
+ }
+
+ jdata, err := json.Marshal(retStruct)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/sms-service/src/sms/handler/handler_test.go b/sms-service/src/sms/handler/handler_test.go
index e1b5b34..5e9e965 100644
--- a/sms-service/src/sms/handler/handler_test.go
+++ b/sms-service/src/sms/handler/handler_test.go
@@ -249,9 +249,16 @@ func TestListSecretHandler(t *testing.T) {
t.Errorf("Expected statusCreated return code. Got: %v", rr.Code)
}
- expected := []string{"testsecret1", "testsecret2"}
+ var expected = struct {
+ SecretNames []string `json:"secretnames"`
+ }{
+ []string{"testsecret1", "testsecret2"},
+ }
+
+ var got struct {
+ SecretNames []string `json:"secretnames"`
+ }
- var got []string
json.NewDecoder(rr.Body).Decode(&got)
if reflect.DeepEqual(expected, got) == false {