fix: listBuckets properly returns wrapped response (#23879)
closes https://github.com/influxdata/influxdb/issues/23861pull/23898/head
parent
a9bf1d54c1
commit
e6e0fd2d9c
|
@ -1082,6 +1082,10 @@ type Bucket struct {
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
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) {
|
func (h *Handler) servePostCreateBucketV2(w http.ResponseWriter, r *http.Request, user meta.User) {
|
||||||
var bs []byte
|
var bs []byte
|
||||||
if r.ContentLength > 0 {
|
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) {
|
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 {
|
if err != nil {
|
||||||
h.httpError(w, fmt.Sprintf("list buckets marshaling error: %s", err.Error()), http.StatusInternalServerError)
|
h.httpError(w, fmt.Sprintf("list buckets marshaling error: %s", err.Error()), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
@ -2212,18 +2212,18 @@ func TestHandler_ListBuckets(t *testing.T) {
|
||||||
t.Fatalf("incorrect error message, expected: %q, got: %q", ct.errMsg, errMsg)
|
t.Fatalf("incorrect error message, expected: %q, got: %q", ct.errMsg, errMsg)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var got []httpd.Bucket
|
var got httpd.Buckets
|
||||||
exp := getBuckets(ct.skip, ct.limit)
|
exp := getBuckets(ct.skip, ct.limit)
|
||||||
|
|
||||||
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
||||||
t.Fatalf("unmarshaling buckets: %s", err.Error())
|
t.Fatalf("unmarshaling buckets: %s", err.Error())
|
||||||
}
|
}
|
||||||
if len(exp) != len(got) {
|
if len(exp) != len(got.Buckets) {
|
||||||
t.Fatalf("expected %d buckets returned, got %d", len(exp), len(got))
|
t.Fatalf("expected %d buckets returned, got %d", len(exp), len(got.Buckets))
|
||||||
}
|
}
|
||||||
for i := 0; i < len(got); i++ {
|
for i := 0; i < len(got.Buckets); i++ {
|
||||||
if exp[i] != got[i].Name {
|
if exp[i] != got.Buckets[i].Name {
|
||||||
t.Fatalf("expected %q, got %q", exp[i], got[i].Name)
|
t.Fatalf("expected %q, got %q", exp[i], got.Buckets[i].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue