Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: listBuckets properly returns wrapped response (#23883) #23884

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ type Bucket struct {
UpdatedAt time.Time `json:"updatedAt"`
}

type Buckets struct {
Buckets []Bucket `json:"buckets"`
}

func (h *Handler) servePostCreateBucketV2(w http.ResponseWriter, r *http.Request, user meta.User) {
var bs []byte
if r.ContentLength > 0 {
Expand Down Expand Up @@ -1457,7 +1461,8 @@ func findBucketIndex(dbs []meta.DatabaseInfo, db string, rp string) (dbIndex int
}

func (h *Handler) sendBuckets(w http.ResponseWriter, buckets []Bucket) {
b, err := json.Marshal(buckets)
bucketsObj := Buckets{buckets}
b, err := json.Marshal(bucketsObj)
if err != nil {
h.httpError(w, fmt.Sprintf("list buckets marshaling error: %s", err.Error()), http.StatusInternalServerError)
return
Expand Down
12 changes: 6 additions & 6 deletions services/httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2212,18 +2212,18 @@ func TestHandler_ListBuckets(t *testing.T) {
t.Fatalf("incorrect error message, expected: %q, got: %q", ct.errMsg, errMsg)
}
} else {
var got []httpd.Bucket
var got httpd.Buckets
exp := getBuckets(ct.skip, ct.limit)

if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
t.Fatalf("unmarshaling buckets: %s", err.Error())
}
if len(exp) != len(got) {
t.Fatalf("expected %d buckets returned, got %d", len(exp), len(got))
if len(exp) != len(got.Buckets) {
t.Fatalf("expected %d buckets returned, got %d", len(exp), len(got.Buckets))
}
for i := 0; i < len(got); i++ {
if exp[i] != got[i].Name {
t.Fatalf("expected %q, got %q", exp[i], got[i].Name)
for i := 0; i < len(got.Buckets); i++ {
if exp[i] != got.Buckets[i].Name {
t.Fatalf("expected %q, got %q", exp[i], got.Buckets[i].Name)
}
}
}
Expand Down