Skip to content

Commit

Permalink
Implement vhosts on [Paged]ListQueuesWithParameters
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
deefdragon committed Oct 26, 2021
1 parent 3c17f84 commit 8d3992d
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
29 changes: 29 additions & 0 deletions queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@ func (c *Client) ListQueuesWithParameters(params url.Values) (rec []QueueInfo, e
return rec, nil
}

// ListQueuesWithParametersIs lists queues with a list of query string values in the vhost vhost.
func (c *Client) ListQueuesWithParametersIn(vhost string, params url.Values) (rec []QueueInfo, err error) {
req, err := newGETRequestWithParameters(c, "queues/"+url.PathEscape(vhost), params)
if err != nil {
return []QueueInfo{}, err
}

if err = executeAndParseRequest(c, req, &rec); err != nil {
return []QueueInfo{}, err
}

return rec, nil
}

// PagedListQueuesWithParameters lists queues with pagination.
func (c *Client) PagedListQueuesWithParameters(params url.Values) (rec PagedQueueInfo, err error) {
req, err := newGETRequestWithParameters(c, "queues", params)
Expand All @@ -284,6 +298,21 @@ func (c *Client) PagedListQueuesWithParameters(params url.Values) (rec PagedQueu

}

// PagedListQueuesWithParameters lists queues with pagination in the vhost vhost.
func (c *Client) PagedListQueuesWithParametersIn(vhost string, params url.Values) (rec PagedQueueInfo, err error) {
req, err := newGETRequestWithParameters(c, "queues/"+url.PathEscape(vhost), params)
if err != nil {
return PagedQueueInfo{}, err
}

if err = executeAndParseRequest(c, req, &rec); err != nil {
return PagedQueueInfo{}, err
}

return rec, nil

}

//
// GET /api/queues/{vhost}
//
Expand Down
82 changes: 82 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,45 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
})
})

Context("GET /queues/{vhost} with arguments", func() {
It("returns decoded response", func() {
conn := openConnection("rabbit/hole")
defer conn.Close()

ch, err := conn.Channel()
Ω(err).Should(BeNil())
defer ch.Close()

_, err = ch.QueueDeclare(
"", // name
false, // durable
false, // auto delete
true, // exclusive
false,
nil)
Ω(err).Should(BeNil())

// give internal events a moment to be
// handled
awaitEventPropagation()

params := url.Values{}
params.Add("lengths_age", "1800")
params.Add("lengths_incr", "30")

qs, err := rmqc.ListQueuesWithParametersIn("", params)
Ω(err).Should(BeNil())

q := qs[0]
Ω(q.Name).ShouldNot(Equal(""))
Ω(q.Node).ShouldNot(BeNil())
Ω(q.Vhost).Should(Equal("rabbit/hole"))
Ω(q.Durable).ShouldNot(BeNil())
Ω(q.Status).ShouldNot(BeEmpty())
Ω(q.MessagesDetails.Samples[0]).ShouldNot(BeNil())
})
})

Context("GET /queues paged with arguments", func() {
It("returns decoded response", func() {
conn := openConnection("/")
Expand Down Expand Up @@ -575,6 +614,49 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
})
})

Context("GET /queues/{vhost} paged with arguments", func() {
It("returns decoded response", func() {
conn := openConnection("rabbit/hole")
defer conn.Close()

ch, err := conn.Channel()
Ω(err).Should(BeNil())
defer ch.Close()

_, err = ch.QueueDeclare(
"", // name
false, // durable
false, // auto delete
true, // exclusive
false,
nil)
Ω(err).Should(BeNil())

// give internal events a moment to be
// handled
awaitEventPropagation()

params := url.Values{}
params.Add("page", "1")

qs, err := rmqc.PagedListQueuesWithParameters(params)
Ω(err).Should(BeNil())

q := qs.Items[0]
Ω(q.Name).ShouldNot(Equal(""))
Ω(q.Node).ShouldNot(BeNil())
Ω(q.Durable).ShouldNot(BeNil())
Ω(q.Status).ShouldNot(BeEmpty())
Ω(qs.Page).Should(Equal(1))
Ω(qs.PageCount).Should(Equal(1))
Ω(qs.ItemCount).ShouldNot(BeNil())
Ω(qs.PageSize).Should(Equal(100))
Ω(qs.TotalCount).ShouldNot(BeNil())
Ω(qs.FilteredCount).ShouldNot(BeNil())
Ω(q.Vhost).Should(Equal("rabbit/hole"))
})
})

Context("GET /queues/{vhost}", func() {
It("returns decoded response", func() {
conn := openConnection("rabbit/hole")
Expand Down

0 comments on commit 8d3992d

Please sign in to comment.