-
-
Notifications
You must be signed in to change notification settings - Fork 7
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 support for GetProjectBatch and GetVersionBatch #73
Conversation
The API for both endpoint is paginated, so this implementation return an iterator that allow the library user to controle how he wants to consume the response.
Hi @zaibon ! thanks so much for the PR. |
pkg/depsdev/v3alpha/api.go
Outdated
NextPageToken string `json:"nextPageToken"` | ||
} | ||
|
||
func getProjectBatch(ctx context.Context, c *client.Client, projectNames []string) <-chan batchJob[def.Project] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 2 methodsgetProjectBatch
and getVersionBatch
are very similar. I wonder if there is a way to refactor them into a single function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a way to extract the duplicate logic.
If you found this becoming too much magic, I can drop the last commit f8e0bd0
@edoardottt I addressed the linting errors. CI is happy now 😄 |
Thank u so much @zaibon. I'm gonna review the PR. Thanks again :) |
At the moment, my implantation does not support requesting a specific page. It only exposes an easy API to walk over all the pages in order. The API itself does not really make it easy to request a specific page because it does not use a number of pages in the request. It uses a token based approach. So you only know the next token after seeing the first page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
Left some thougths, waiting to read what you think about :)
|
||
func TestGetProjectBatch(t *testing.T) { | ||
t.Run("GetProject batch", func(t *testing.T) { | ||
iter, err := api.GetProjectBatch([]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This input returns a response with 3 items in a single page. Can we have a test checking for correct results in paginated results too?
We don't have to check the responses' content, just if the items count match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test that returns 300 results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
results, err := consumeIter(iter) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, expected, results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like previously in other discussions, I don't know if this is the best way to check the correctness of code.
E.g. I could release a new version of defangjs and this test case will fail :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it will not since we're requesting details of a specific version. The logic is the same used in the TestGetVersion
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Thanks so much @zaibon ! |
The API for both endpoint is paginated, so this implementation return an iterator that allow the library user to controle how he wants to consume the response.