-
Notifications
You must be signed in to change notification settings - Fork 16
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
Added tests for Cloud Events and verification of reception of events by the Sink #93
Conversation
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 have found some other improvements not specific to the PR:
- I haven't seen any clean-up for eventing-manager in cleanup_test go files. Do we delete it at the endo file.
- We need to correct the comment
- We need to join errors in test cases so that we show all differences so that we see all at once. You can use errrors.Join
func (te *TestEnvironment) CompareCloudEvents(expectedEvent cloudevents.Event, gotEvent cloudevents.Event) error { | ||
// check if its a valid CloudEvent. | ||
if err := gotEvent.Validate(); err != nil { | ||
return fmt.Errorf("expected valid cloud event, but got invalid cloud event. Error: %s", err.Error()) | ||
} | ||
|
||
if expectedEvent.ID() != gotEvent.ID() { | ||
return fmt.Errorf("expected event ID: %s, got event ID: %s", expectedEvent.ID(), gotEvent.ID()) | ||
} | ||
|
||
if string(expectedEvent.Data()) != string(gotEvent.Data()) { | ||
return fmt.Errorf("expected event data: %s, got event data: %s", | ||
string(expectedEvent.Data()), string(gotEvent.Data())) | ||
} | ||
|
||
// if it is a v1alpha1 Subscription event, then we do not check further. | ||
if strings.HasPrefix(gotEvent.Type(), te.TestConfigs.EventTypePrefix) { | ||
return nil | ||
} | ||
|
||
// check in detail further the source and type. | ||
if expectedEvent.Source() != gotEvent.Source() { | ||
return fmt.Errorf("expected event Source: %s, got event Source: %s", expectedEvent.Source(), gotEvent.Source()) | ||
} | ||
|
||
if expectedEvent.Type() != gotEvent.Type() { | ||
return fmt.Errorf("expected event Type: %s, got event Type: %s", expectedEvent.Type(), gotEvent.Type()) | ||
} | ||
|
||
originalType, ok := gotEvent.Extensions()[fixtures.EventOriginalTypeHeader] | ||
if !ok { | ||
return fmt.Errorf("expected event to have header: %s, but its missing", fixtures.EventOriginalTypeHeader) | ||
} | ||
if expectedEvent.Type() != originalType { | ||
return fmt.Errorf("expected originaltype header to have value: %s, but got: %s", expectedEvent.Type(), originalType) | ||
} |
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'd be nice if we can collect all the errors wiht errors.Join so that we can see at once what are all differences. Otherwise, it returns and the following differences are not shown.
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.
updated
func (te *TestEnvironment) VerifyCloudEventReceivedBySink(expectedEvent cloudevents.Event) error { | ||
// define the event | ||
gotSinkEvent, err := te.SinkClient.GetEventFromSinkWithRetries(expectedEvent.ID(), Attempts, Interval) | ||
if err != nil { | ||
te.Logger.Debug(err.Error()) |
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.
is this error not displayed twice in the log as error is returned to the main test case? You should have seen the logs.
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 is printed here so we can see the progress during the multiple retries.
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.
Can we make a common function to pass message, subscriptions, CRD version (v1alpha1/2) and CE encoding. Let's keep test cases as they are, but to extract to a common function for iterating subscriptions and testing them. It seems to me lots of repetitive code.
For example,
function testEventDelivery(subsctipions, encoding, crdVersion) {
for _, subToTest := range subscriptions {
subToTest := subToTest
for _, eventTypeToTest := range subToTest.Types {
eventTypeToTest := eventTypeToTest
testName := fmt.Sprintf("legacy event should work for subscription: %s with type: %s", subToTest.Name, eventTypeToTest)
// run test for the eventType.
t.Run(testName, func(t *testing.T) {
t.Parallel()
// when
err := common.Retry(testenvironment.ThreeAttempts, testenvironment.Interval, func() error {
return testEnvironment.TestDeliveryOfLegacyEvent("", eventTypeToTest, crdVersion, encoding)
})
// then
require.NoError(t, 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.
updated
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 have found some other improvements not specific to the PR:
- I haven't seen any clean-up for eventing-manager in cleanup_test go files. Do we delete it e2e/cleanup/cleanup_test.go?
- We need to correct the comment
- We need to join errors in test cases so that we show all differences so that we see all at once. You can use errors.Join
- Are the errors are not displayed twice? Let's run them together and check how to it looks.
We are not deploying |
Description
Changes proposed in this pull request:
Related issue(s)