-
Notifications
You must be signed in to change notification settings - Fork 2
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: grail filter segments client #135
base: main
Are you sure you want to change the base?
Conversation
295719b
to
429ee69
Compare
87361f2
to
e902702
Compare
var getRequestOptions = rest.RequestOptions{ | ||
CustomShouldRetryFunc: rest.RetryIfTooManyRequests, | ||
QueryParams: map[string][]string{ | ||
"add-fields": {"INCLUDES", "VARIABLES", "RESOURCECONTEXT"}, |
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.
These differ from the other fields, why is that? Is it not necessary?
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.
By default, not all parts of the configuration are included. If a user doesn't specify what exactly it needs, we assume that it requests everything.
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 question is why the ExteralId
is missing here, as the list
queries all by default.
To the points mentioned above, please also add documentation to all public methods, with all the assumptions and special cases we're taking |
f734a74
to
e15bb00
Compare
Signed-off-by: Bernd Warmuth <[email protected]>
c006cc9
to
8042673
Compare
8042673
to
22ba664
Compare
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.
Major points that are still required:
-
0% test coverage of the filtersegments. I gave an example in my comments.
a) This is because of the mocks. We should do fakes instead of mocks and use a local server and respond the HTTP results directly. Then, the inner code would be tested.
b) Because of that, a real bug was not detected that should have been easily detectable, as it's not even in the method doc. -
Inconsistent error return values. Sometimes you return a plain
err
, sometimes you wrap it. Please consistently wrap it. -
The inner test names are not consistent in
clients/grailfiltersegments/filtersegment_test.go
} | ||
|
||
// set default behavior to pick all information by default | ||
if ro.QueryParams == nil && ro.QueryParams.Has("add-fields") { |
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.
if ro.QueryParams == nil && ro.QueryParams.Has("add-fields") { | |
if ro.QueryParams == nil && !ro.QueryParams.Has("add-fields") { |
When I saw this, I noticed that there are no unit tests at all present. Please add some.
For this small check, I came up with this test:
func TestGet_AllFieldsArePresentIfNotSpecified(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Log(r.URL.String())
fields := r.URL.Query()["add-fields"]
require.ElementsMatch(t, []string{"INCLUDES", "VARIABLES", "EXTERNALID", "RESOURCECONTEXT"}, fields)
}))
defer server.Close()
u, err := url.Parse(server.URL)
require.NoError(t, err)
c := NewClient(rest.NewClient(u, server.Client()))
resp, err := c.Get(context.TODO(), "id", rest.RequestOptions{})
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}
Please add some basic tests for all endpoints, e.g. input validation
|
||
func (c Client) List(ctx context.Context) (*http.Response, error) { | ||
path := endpointPath + ":lean" // minimal set of information is enough | ||
return c.client.GET(ctx, path, rest.RequestOptions{CustomShouldRetryFunc: rest.RetryIfTooManyRequests}) |
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.
One more thing I noticed: Sometimes (like here) you are directly returning from the client, while in other cases (like Create
) you are checking err
and add context to it. I'd suggest doing this everywhere, so here and in Update
adding fetching all items failed
or updating failed
below
var getRequestOptions = rest.RequestOptions{ | ||
CustomShouldRetryFunc: rest.RetryIfTooManyRequests, | ||
QueryParams: map[string][]string{ | ||
"add-fields": {"INCLUDES", "VARIABLES", "RESOURCECONTEXT"}, |
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 question is why the ExteralId
is missing here, as the list
queries all by default.
func (c Client) GetAll(ctx context.Context) ([]Response, error) { | ||
listResp, err := c.List(ctx) | ||
if err != nil { | ||
return nil, err |
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.
Here you're doing something similar to what I commented before: Sometimes you do add information to the errors, sometimes you don't (e.g. L124 you add information). I suggest adding everywhere the context what's going wrong. Please have a look where you only return the err
without extra information and add some.
|
||
func TestUpsert(t *testing.T) { | ||
|
||
t.Run("Create - Create OK", func(t *testing.T) { |
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.
Similar to the other file, the prefix is not needed. Here it's even wrong
t.Run("Create - Create OK", func(t *testing.T) { | |
t.Run("Creates if config does not exist", func(t *testing.T) { |
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 file has 0% test coverage
assert.ErrorAs(t, err, &api.APIError{}) | ||
|
||
var apiErr api.APIError | ||
errors.As(err, &apiErr) |
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.
errors.As(err, &apiErr) | |
`assert.ErrorAs(t, err, &apiErr)` |
Nit: This will check that the error is really of that type. Otherwise, you are currently silently swallowing the error. In case the As
would fail, the Equals after will fail, but we would not know why/what error type it really was
To update an OpenPipeline configuration, the `updateToken` must be either empty, or set to the latest version. To be consistent with existing code, we set the `updateToken`.
What this PR does / Why we need it:
This PR introduces the http client for grail filter segments to be used by monaco and terraform.
Special notes for your reviewer:
Does this PR introduce a user-facing change?