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

feat: add name and with_count params into listing queues #2018

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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