Skip to content

Commit

Permalink
feat: add name and with_count params into listing queues (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
galuszkak committed Sep 15, 2020
1 parent e77d083 commit 9bd60a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions openstack/messaging/v2/queues/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type ListOpts struct {

// Specifies if showing the detailed information when querying queues
Detailed bool `q:"detailed,omitempty"`

// Specifies if filter the queues by queue’s name when querying queues.
Name bool `q:"name,omitempty"`

// Specifies if showing the amount of queues when querying them.
WithCount bool `q:"with_count,omitempty"`
}

// ToQueueListQuery formats a ListOpts into a query string.
Expand Down
12 changes: 12 additions & 0 deletions openstack/messaging/v2/queues/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ func (r QueuePage) NextPageURL() (string, error) {
return nextPageURL(r.URL.String(), next)
}

// GetCount value if it request was supplied `WithCount` param
func (r QueuePage) GetCount() (int, error) {
var s struct {
Count int `json:"count"`
}
err := r.ExtractInto(&s)
if err != nil {
return 0, err
}
return s.Count, nil
}

func (r *QueueDetails) UnmarshalJSON(b []byte) error {
type tmp QueueDetails
var s struct {
Expand Down
8 changes: 5 additions & 3 deletions openstack/messaging/v2/queues/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const ListQueuesResponse1 = `
"href":"/v2/queues?marker=london",
"rel":"next"
}
]
],
"count": 2
}`

// ListQueuesResponse2 is a sample response to a List queues.
Expand All @@ -90,7 +91,8 @@ const ListQueuesResponse2 = `
"href":"/v2/queues?marker=beijing",
"rel":"next"
}
]
],
"count": 2
}`

// UpdateQueueRequest is a sample request to update a queue.
Expand Down Expand Up @@ -223,7 +225,7 @@ func HandleListSuccessfully(t *testing.T) {
next := r.RequestURI

switch next {
case "/v2/queues?limit=1":
case "/v2/queues?limit=1&with_count=true":
fmt.Fprintf(w, ListQueuesResponse1)
case "/v2/queues?marker=london":
fmt.Fprint(w, ListQueuesResponse2)
Expand Down
8 changes: 6 additions & 2 deletions openstack/messaging/v2/queues/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ func TestList(t *testing.T) {
HandleListSuccessfully(t)

listOpts := queues.ListOpts{
Limit: 1,
Limit: 1,
WithCount: true,
}

count := 0
err := queues.List(fake.ServiceClient(), listOpts).EachPage(func(page pagination.Page) (bool, error) {
actual, err := queues.ExtractQueues(page)
th.AssertNoErr(t, err)
countField, err := page.(queues.QueuePage).GetCount()

th.AssertNoErr(t, err)
th.AssertEquals(t, countField, 2)

th.CheckDeepEquals(t, ExpectedQueueSlice[count], actual)
count++

return true, nil
})
th.AssertNoErr(t, err)
Expand Down

0 comments on commit 9bd60a2

Please sign in to comment.