fix: listBuckets properly returns wrapped response (#23879)

closes https://github.com/influxdata/influxdb/issues/23861
pull/23898/head
Vlasta Hajek 2022-11-09 18:05:21 +01:00 committed by GitHub
parent a9bf1d54c1
commit e6e0fd2d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -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 {
@ -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

View File

@ -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)
}
}
}