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

Aim namespace tests for apps and dashboards #610

Merged
merged 15 commits into from
Nov 20, 2023

Conversation

suprjinx
Copy link
Contributor

@suprjinx suprjinx commented Nov 16, 2023

This PR includes new "flow" tests for Aim Apps and Dashboards with particular testing of namespace scoping.

Also, the Apps endpoints were not filtering by namespace for GET, PUT, and DELETE -- added where clauses for this.
Fixes #609

@suprjinx suprjinx marked this pull request as ready for review November 17, 2023 19:16
@suprjinx suprjinx changed the title Aim ns tests apps dashboards Aim namespace tests for apps and dashboards Nov 17, 2023
Copy link
Collaborator

@dsuhinin dsuhinin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General moments:

  • please do not create instance of AIM client just request.
  • GET method is by default so you don't need to specify it.
  • JSON response type is by default so you don't need to specify it.
  • fmt.Sprinf - you can avoid this moment.

for _, nsCode := range []string{"default", tt.namespace1Code, tt.namespace2Code} {
// ignore errors here since default exists on first run
//nolint:errcheck
_, _ = s.NamespaceFixtures.CreateNamespace(context.Background(), &models.Namespace{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please in any case check all errors?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep and it will be really nice to clean and then start.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 100 to 116
require.Nil(
s.T(),
s.AIMClient().WithMethod(
http.MethodGet,
).WithNamespace(
namespace1Code,
).WithResponseType(
helpers.ResponseTypeJSON,
).WithResponse(
&resp,
).DoRequest(
"/apps",
),
)
// only app 1 should be present
assert.Equal(s.T(), 1, len(resp))
assert.Equal(s.T(), app1ID, resp[0].ID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you didn't wrap it into method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted methods for the "positive" tests, but left error expectations in the main test method (awkward to share a method for this)


// IDs from other namespace cannot be fetched, updated, or deleted
errResp := response.Error{}
client := s.AIMClient()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you create each time instance? please merge main if you haven't done this yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i need to hold instance of client to retrieve status code for assertion

Comment on lines +142 to +144
client.WithMethod(
http.MethodGet,
).WithNamespace(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to specify method anymore. GET is by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case it makes it clear we are testing the get method, yes? if implicit, that is not so obvious from reading test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but that's why we have default values inside to do not overwrite/set each time them like probably many other packages in go or any other language.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other tests do have to indicate the http method, so i think it's reasonable to include here for symmetry.

tests/integration/golang/aim/namespace/flows/app_test.go Outdated Show resolved Hide resolved
tests/integration/golang/aim/namespace/flows/app_test.go Outdated Show resolved Hide resolved
).WithResponse(
&errResp,
).DoRequest(
fmt.Sprintf("/apps/%s", app1ID),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just that we don't need to use fmt.Sprintf. it will be done under the hood automatically =). I added this moment for just forgot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick with what is expected by most programmers (use fmt.Sprintf for template string + values).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you can just pass DoRequest("/apps/%s", app1ID) like for example in errors.Errorf() function. You don't need to pass sprintf here, because sprintf is under the hood probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a surprising behavior. Maybe add DoRequestf() to indicate templating is available?

assert.Equal(s.T(), fiber.StatusOK, client.GetStatusCode())
}

func (s *AppFlowTestSuite) createApp(namespace string, req *request.CreateApp) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename methods where you compare to have AndCompare in the name so we can understand what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

@dsuhinin dsuhinin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few comments but looks good!

@suprjinx suprjinx merged commit 7ccd506 into G-Research:main Nov 20, 2023
@suprjinx suprjinx deleted the aim-ns-tests-apps-dashboards branch November 20, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIM namespace integration tests (apps and dashboards)
2 participants