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

Added tests for Cloud Events and verification of reception of events by the Sink #93

Merged
merged 8 commits into from
Sep 14, 2023

Conversation

mfaizanse
Copy link
Member

Description

Changes proposed in this pull request:

  • Added tests for Cloud Events and verification of reception of events by the Sink

Related issue(s)

@mfaizanse mfaizanse requested a review from a team as a code owner September 13, 2023 08:27
@mfaizanse mfaizanse requested a review from muralov September 13, 2023 08:27
@kyma-bot kyma-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 13, 2023
Copy link
Contributor

@muralov muralov left a 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

Comment on lines 438 to 473
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)
}
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

image

Copy link
Member Author

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())
Copy link
Contributor

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.

Copy link
Member Author

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.

hack/e2e/eventing/delivery/delivery_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

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)
			})
		}
	}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor

@muralov muralov left a 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.

@mfaizanse
Copy link
Member Author

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 eventing-manager deployment as part of these tests, so thats why we are not deleting it in the cleanup.

@kyma-bot kyma-bot added the lgtm Looks good to me! label Sep 14, 2023
@kyma-bot kyma-bot merged commit 343a348 into kyma-project:main Sep 14, 2023
@mfaizanse mfaizanse deleted the e2e_test3 branch September 14, 2023 07:37
@mfaizanse mfaizanse linked an issue Sep 14, 2023 that may be closed by this pull request
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Looks good to me! size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement e2e tests using golang for eventing-manager
3 participants