summaryrefslogtreecommitdiffstats
path: root/sms-service/src
diff options
context:
space:
mode:
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 {