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

Return 404 from GET Bindings for Expired Bindings #1355

Conversation

ralikio
Copy link
Member

@ralikio ralikio commented Oct 17, 2024

Description

Changes proposed in this pull request:

  • returning 404 error code from API GET bindings in case of binding expiration,
  • a test case for above.

Related issue(s)

#284

@ralikio ralikio requested a review from a team as a code owner October 17, 2024 13:31
@kyma-bot kyma-bot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 17, 2024
@kyma-gopher-bot kyma-gopher-bot enabled auto-merge (squash) October 17, 2024 13:31
@kyma-bot kyma-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 17, 2024
@ralikio ralikio added the kind/bug Categorizes issue or PR as related to a bug. label Oct 17, 2024

t.Run("should return 404 code for the expired binding", func(t *testing.T) {
// given
mockBindings := new(mocks.Bindings)
Copy link
Member

Choose a reason for hiding this comment

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

just a question, why just not use in-memory implementation?

Copy link
Member Author

@ralikio ralikio Oct 17, 2024

Choose a reason for hiding this comment

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

  1. With mocks I am guaranteed the bindings' "Get" method is called.
  2. I do not need to check if anything has been created in the test, it just for quick return and assertion that 404 is returned when for prefabricated binding.

Copy link
Member

Choose a reason for hiding this comment

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

We are using in memory implementation in other unit test which works fine, I don't like to introduce a different solution which does not give us any special value. Such pattern is also used in fake kubernetes client. Mocking database can be risky.
The title of the test is "should return 404 code for the expired binding", not "should call 'get' method", it is not important in my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still find value in asserting execution. In order to meet the argument of unnecessary test modifications when interface changes and mock regeneration is required I would suggest to treat interface as something that rarely should change or rely on new interfaces in new logic.

Done as requested though. Let's discuss offline what are the possibilities to use spies or sth else to assert method executions in our project.

Copy link
Contributor

@jaroslaw-pieszka jaroslaw-pieszka Oct 18, 2024

Choose a reason for hiding this comment

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

It's not about interface changing but implementation changing. We relied on implementation (test relied on the knowledge how logic is implemented) which in this case I found excessive, or even inappropriate.

Copy link
Member Author

@ralikio ralikio Oct 18, 2024

Choose a reason for hiding this comment

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

No, that is not true. The test contained assertion on logic so that in the future if our "black box" called bindings multiple times we would know that it is not aligned with initial assumptions. Think about it not as an assertion if specific instruction that the unit uses but as requirement introduced because unit relies on external dependency in the form of "Bindings" interface. In the current form, we could remove Bindings dependency, return 404 with correct message from the unit and the test would be green. The Bindings interface is external, not internal to the tested unit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I beg to disagree. Test assumed that implementation calls Get method once. This is not part of contract.

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming that we test contract and use black-box testing, we do not need to know that there is any external dependency, we do not need to know how it is implemented, how many invocations of any kind is made.
We know only, that if the binding in question is expired, we get 404.

Copy link
Member

Choose a reason for hiding this comment

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

We can testing if there is only one Get call on repository, but... then we should test if the binding manager deletes... deployments or something else by accident. We cannot test everything! such tests would be a problem, not a help

@kyma-project kyma-project deleted a comment from github-actions bot Oct 17, 2024
@kyma-bot kyma-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 18, 2024
@kyma-gopher-bot kyma-gopher-bot merged commit 09358b7 into kyma-project:main Oct 18, 2024
29 checks passed
@kyma-bot kyma-bot added the lgtm Looks good to me! label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indicates the PR's author has signed the CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm Looks good to me! size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants