This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for passing in skip and top parameters to calls that list subsc…
…riptions, queues and topics #234 The current implementation that lists resources (using ATOM) doesn't allow passing in skip, which would allow you to list more than the default page size of 100 items. This PR adds in skip (and top, which controls the size of the page) for listing queues, topics and subscriptions which allows you, over multiple calls and incrementing skip, to get the list of all entities. Fixes #231
- Loading branch information
Showing
10 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// ConstructAtomPath adds the proper parameters for skip and top | ||
// This is common for the list operations for queues, topics and subscriptions. | ||
func ConstructAtomPath(basePath string, skip int, top int) string { | ||
values := url.Values{} | ||
|
||
if skip > 0 { | ||
values.Add("$skip", fmt.Sprintf("%d", skip)) | ||
} | ||
|
||
if top > 0 { | ||
values.Add("$top", fmt.Sprintf("%d", top)) | ||
} | ||
|
||
if len(values) == 0 { | ||
return basePath | ||
} | ||
|
||
return fmt.Sprintf("%s?%s", basePath, values.Encode()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConstructAtomPath(t *testing.T) { | ||
basePath := ConstructAtomPath("/something", 1, 2) | ||
|
||
// I'm assuming the ordering is non-deterministic since the underlying values are just a map | ||
assert.Truef(t, basePath == "/something?%24skip=1&%24top=2" || basePath == "/something?%24top=2&%24skip=1", "%s wasn't one of our two variations", basePath) | ||
|
||
basePath = ConstructAtomPath("/something", 0, -1) | ||
assert.EqualValues(t, "/something", basePath, "Values <= 0 are ignored") | ||
|
||
basePath = ConstructAtomPath("/something", -1, 0) | ||
assert.EqualValues(t, "/something", basePath, "Values <= 0 are ignored") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters