-
Notifications
You must be signed in to change notification settings - Fork 22
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
Merged
kyma-gopher-bot
merged 12 commits into
kyma-project:main
from
ralikio:bugfixes/not-found-for-expired-bindings
Oct 18, 2024
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b7528f
Bindings Mock
ralikio 6b4b0f8
404 on Expired Bindings
ralikio 8a19052
Merge branch 'main' into bugfixes/not-found-for-expired-bindings
ralikio 23488c5
Review Remarks - https://github.com/kyma-project/kyma-environment-bro…
ralikio 5deaec5
Linter
ralikio 900f24a
Test Adding New Method
ralikio afb3b56
Review Remarks
ralikio 2f2bc0b
Linter & Error Correction
ralikio c84dc56
Update ext.go
ralikio a67d803
Update binding.go
ralikio c5234f7
Update binding.go
ralikio 1afb35f
Delete internal/storage/automock/bindings.go
ralikio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package broker | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kyma-project/kyma-environment-broker/internal" | ||
mocks "github.com/kyma-project/kyma-environment-broker/internal/storage/automock" | ||
"github.com/pivotal-cf/brokerapi/v8/domain" | ||
"github.com/pivotal-cf/brokerapi/v8/domain/apiresponses" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetBinding(t *testing.T) { | ||
|
||
t.Run("should return 404 code for the expired binding", func(t *testing.T) { | ||
// given | ||
mockBindings := new(mocks.Bindings) | ||
|
||
expiredBinding := &internal.Binding{ | ||
ExpiresAt: time.Now().Add(-1 * time.Hour), | ||
} | ||
|
||
mockBindings.On("Get", "test-instance-id", "test-binding-id").Return(expiredBinding, nil) | ||
|
||
endpoint := &GetBindingEndpoint{ | ||
bindings: mockBindings, | ||
log: &logrus.Logger{}, // Assuming you have a mock logger | ||
} | ||
|
||
// when | ||
_, err := endpoint.GetBinding(context.Background(), "test-instance-id", "test-binding-id", domain.FetchBindingDetails{}) | ||
|
||
// then | ||
require.NotNil(t, err) | ||
apiErr, ok := err.(*apiresponses.FailureResponse) | ||
require.True(t, ok) | ||
require.Equal(t, http.StatusNotFound, apiErr.ValidatedStatusCode(nil)) | ||
jaroslaw-pieszka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mockBindings.AssertExpectations(t) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just a question, why just not use in-memory implementation?
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.
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.
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.
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.
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.
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.
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.
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, 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.
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.
I beg to disagree. Test assumed that implementation calls
Get
method once. This is not part of contract.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.
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.
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.
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