diff --git a/test/e2e/broker_channel_flow_test.go b/test/e2e/broker_channel_flow_test.go index aeea5e35c78..58aafbf7b60 100644 --- a/test/e2e/broker_channel_flow_test.go +++ b/test/e2e/broker_channel_flow_test.go @@ -24,7 +24,7 @@ import ( ) /* -TestEventTransformationForTrigger tests the following topology: +TestBrokerChannelFlow tests the following topology: ------------- ---------------------- | | | | @@ -44,5 +44,5 @@ Trigger3 filters the transformed event and sends it to Channel. */ func TestBrokerChannelFlow(t *testing.T) { - helpers.BrokerChannelFlowTestHelper(t, brokerClass, channelTestRunner) + helpers.BrokerChannelFlowWithTransformation(t, brokerClass, channelTestRunner) } diff --git a/test/e2e/broker_config_test.go b/test/e2e/broker_config_test.go deleted file mode 100644 index 9ce7aed6a14..00000000000 --- a/test/e2e/broker_config_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build e2e - -/* -Copyright 2020 The Knative Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package e2e - -import ( - "testing" - - "knative.dev/eventing/test/e2e/helpers" -) - -// TestBrokerWithConfig tests Broker using Config instead of channel templates. -func TestBrokerWithConfig(t *testing.T) { - helpers.TestBrokerWithConfig(t, brokerClass, channelTestRunner) -} diff --git a/test/e2e/broker_dls_test.go b/test/e2e/broker_dls_test.go deleted file mode 100644 index d54378f51a2..00000000000 --- a/test/e2e/broker_dls_test.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build e2e - -/* -Copyright 2020 The Knative Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package e2e - -import ( - "testing" - - "knative.dev/eventing/test/e2e/helpers" -) - -// TestBrokerDeadLetterSink tests Broker's DeadLetterSink -func TestBrokerDeadLetterSink(t *testing.T) { - helpers.TestBrokerWithConfig(t, brokerClass, channelTestRunner) -} diff --git a/test/e2e/broker_default_test.go b/test/e2e/broker_with_many_triggers_test.go similarity index 100% rename from test/e2e/broker_default_test.go rename to test/e2e/broker_with_many_triggers_test.go diff --git a/test/e2e/helpers/broker_with_config_helper.go b/test/e2e/helpers/broker_channel_flow_helper.go similarity index 88% rename from test/e2e/helpers/broker_with_config_helper.go rename to test/e2e/helpers/broker_channel_flow_helper.go index 4ea1eea94e4..7dcb97135b3 100644 --- a/test/e2e/helpers/broker_with_config_helper.go +++ b/test/e2e/helpers/broker_channel_flow_helper.go @@ -29,8 +29,27 @@ import ( "knative.dev/eventing/test/lib/resources" ) -// TestBrokerWithConfig is the helper function for broker_with_config_test -func TestBrokerWithConfig(t *testing.T, +/* +BrokerChannelFlowWithTransformation tests the following topology: + + ------------- ---------------------- + | | | | + v | v | +EventSource ---> Broker ---> Trigger1 -------> Service(Transformation) + | + | + |-------> Trigger2 -------> Service(Logger1) + | + | + |-------> Trigger3 -------> Channel --------> Subscription --------> Service(Logger2) + +Explanation: +Trigger1 filters the orignal event and tranforms it to a new event, +Trigger2 logs all events, +Trigger3 filters the transformed event and sends it to Channel. + +*/ +func BrokerChannelFlowWithTransformation(t *testing.T, brokerClass string, channelTestRunner lib.ChannelTestRunner, options ...lib.SetupClientOption) { diff --git a/test/e2e/helpers/broker_channel_flow_test_helper.go b/test/e2e/helpers/broker_channel_flow_test_helper.go deleted file mode 100644 index 49d0d80eb67..00000000000 --- a/test/e2e/helpers/broker_channel_flow_test_helper.go +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright 2019 The Knative Authors -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package helpers - -import ( - "fmt" - "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/uuid" - - "knative.dev/eventing/pkg/apis/eventing/v1beta1" - "knative.dev/eventing/test/lib" - "knative.dev/eventing/test/lib/cloudevents" - "knative.dev/eventing/test/lib/resources" -) - -// BrokerChannelFlowTestHelper is the helper function for broker_channel_flow_test -func BrokerChannelFlowTestHelper(t *testing.T, - brokerClass string, - channelTestRunner lib.ChannelTestRunner, - options ...lib.SetupClientOption) { - const ( - senderName = "e2e-brokerchannel-sender" - brokerName = "e2e-brokerchannel-broker" - - any = v1beta1.TriggerAnyFilter - eventType1 = "type1" - eventType2 = "type2" - eventSource1 = "source1" - eventSource2 = "source2" - eventBody = "e2e-brokerchannel-body" - - triggerName1 = "e2e-brokerchannel-trigger1" - triggerName2 = "e2e-brokerchannel-trigger2" - triggerName3 = "e2e-brokerchannel-trigger3" - - transformationPodName = "e2e-brokerchannel-trans-pod" - loggerPodName1 = "e2e-brokerchannel-logger-pod1" - loggerPodName2 = "e2e-brokerchannel-logger-pod2" - - channelName = "e2e-brokerchannel-channel" - subscriptionName = "e2e-brokerchannel-subscription" - ) - - channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { - client := lib.Setup(st, true, options...) - defer lib.TearDown(client) - - // Create a configmap used by the broker. - client.CreateBrokerConfigMapOrFail(brokerName, &channel) - - // create a new broker - client.CreateBrokerV1Beta1OrFail(brokerName, - resources.WithBrokerClassForBrokerV1Beta1(brokerClass), - resources.WithConfigMapForBrokerConfig()) - client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta) - - // create the event we want to transform to - transformedEventBody := fmt.Sprintf("%s %s", eventBody, string(uuid.NewUUID())) - eventAfterTransformation := cloudevents.New( - fmt.Sprintf(`{"msg":%q}`, transformedEventBody), - cloudevents.WithSource(eventSource2), - cloudevents.WithType(eventType2), - ) - - // create the transformation service for trigger1 - transformationPod := resources.DeprecatedEventTransformationPod(transformationPodName, eventAfterTransformation) - client.CreatePodOrFail(transformationPod, lib.WithService(transformationPodName)) - - // create trigger1 to receive the original event, and do event transformation - client.CreateTriggerOrFailV1Beta1( - triggerName1, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource1, eventType1, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), - ) - - // create logger pod and service for trigger2 - loggerPod1 := resources.EventLoggerPod(loggerPodName1) - client.CreatePodOrFail(loggerPod1, lib.WithService(loggerPodName1)) - - // create trigger2 to receive all the events - client.CreateTriggerOrFailV1Beta1( - triggerName2, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(any, any, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(loggerPodName1), - ) - - // create channel for trigger3 - client.CreateChannelOrFail(channelName, &channel) - client.WaitForResourceReadyOrFail(channelName, &channel) - - // create trigger3 to receive the transformed event, and send it to the channel - channelURL, err := client.GetAddressableURI(channelName, &channel) - if err != nil { - st.Fatalf("Failed to get the url for the channel %q: %v", channelName, err) - } - client.CreateTriggerOrFailV1Beta1( - triggerName3, - resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource2, eventType2, nil), - resources.WithSubscriberURIForTriggerV1Beta1(channelURL), - ) - - // create logger pod and service for subscription - loggerPod2 := resources.EventLoggerPod(loggerPodName2) - client.CreatePodOrFail(loggerPod2, lib.WithService(loggerPodName2)) - - // create subscription - client.CreateSubscriptionOrFail( - subscriptionName, - channelName, - &channel, - resources.WithSubscriberForSubscription(loggerPodName2), - ) - - // wait for all test resources to be ready, so that we can start sending events - client.WaitForAllTestResourcesReadyOrFail() - - // send fake CloudEvent to the broker - eventToSend := cloudevents.New( - fmt.Sprintf(`{"msg":%q}`, eventBody), - cloudevents.WithSource(eventSource1), - cloudevents.WithType(eventType1), - ) - client.SendFakeEventToAddressableOrFail(senderName, brokerName, lib.BrokerTypeMeta, eventToSend) - - // check if trigger2's logging service receives both events - eventBodies := []string{transformedEventBody, eventBody} - if err := client.CheckLog(loggerPodName1, lib.CheckerContainsAll([]string{transformedEventBody, eventBody})); err != nil { - st.Fatalf("Strings %v not found in logs of logger pod %q: %v", eventBodies, loggerPodName1, err) - } - - // check if subscription's logging service receives the transformed event - if err := client.CheckLog(loggerPodName2, lib.CheckerContains(transformedEventBody)); err != nil { - st.Fatalf("Strings %q not found in logs of logger pod %q: %v", transformedEventBody, loggerPodName2, err) - } - }) -} diff --git a/test/e2e/helpers/broker_event_transformation_test_helper.go b/test/e2e/helpers/broker_event_transformation_test_helper.go index 5273828221b..413a1ec9f5d 100644 --- a/test/e2e/helpers/broker_event_transformation_test_helper.go +++ b/test/e2e/helpers/broker_event_transformation_test_helper.go @@ -16,19 +16,33 @@ limitations under the License. package helpers import ( - "fmt" "testing" + cloudevents "github.com/cloudevents/sdk-go/v2" + . "github.com/cloudevents/sdk-go/v2/test" + "github.com/google/uuid" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/uuid" "knative.dev/eventing/pkg/apis/eventing/v1beta1" "knative.dev/eventing/test/lib" - "knative.dev/eventing/test/lib/cloudevents" + "knative.dev/eventing/test/lib/recordevents" "knative.dev/eventing/test/lib/resources" ) -// EventTransformationForTriggerTestHelper is the helper function for broker_event_tranformation_test +/* +EventTransformationForTriggerTestHelper tests the following scenario: + + 5 4 + ------------- ---------------------- + | | | | + 1 v 2 | v 3 | +EventSource ---> Broker ---> Trigger1 -------> Service(Transformation) + | + | 6 7 + |-------> Trigger2 -------> Service(Logger) + +Note: the number denotes the sequence of the event that flows in this test case. +*/ func EventTransformationForTriggerTestHelper(t *testing.T, brokerClass string, channelTestRunner lib.ChannelTestRunner, @@ -37,18 +51,19 @@ func EventTransformationForTriggerTestHelper(t *testing.T, senderName = "e2e-eventtransformation-sender" brokerName = "e2e-eventtransformation-broker" - any = v1beta1.TriggerAnyFilter - eventType1 = "type1" - eventType2 = "type2" - eventSource1 = "source1" - eventSource2 = "source2" - eventBody = "e2e-eventtransformation-body" + any = v1beta1.TriggerAnyFilter + eventType = "type1" + transformedEventType = "type2" + eventSource = "source1" + transformedEventSource = "source2" + eventBody = `{"msg":"e2e-eventtransformation-body"}` + transformedBody = `{"msg":"transformed body"}` - triggerName1 = "trigger1" - triggerName2 = "trigger2" + originalTriggerName = "trigger1" + transformedTriggerName = "trigger2" transformationPodName = "trans-pod" - loggerPodName = "logger-pod" + recordEventsPodName = "recordevents-pod" ) channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { @@ -62,52 +77,59 @@ func EventTransformationForTriggerTestHelper(t *testing.T, client.CreateBrokerV1Beta1OrFail(brokerName, resources.WithBrokerClassForBrokerV1Beta1(brokerClass), resources.WithConfigForBrokerV1Beta1(config)) client.WaitForResourceReadyOrFail(brokerName, lib.BrokerTypeMeta) - // create the event we want to transform to - transformedEventBody := fmt.Sprintf("%s %s", eventBody, string(uuid.NewUUID())) - eventAfterTransformation := cloudevents.New( - fmt.Sprintf(`{"msg":%q}`, transformedEventBody), - cloudevents.WithSource(eventSource2), - cloudevents.WithType(eventType2), - ) - // create the transformation service - transformationPod := resources.DeprecatedEventTransformationPod(transformationPodName, eventAfterTransformation) + transformationPod := resources.EventTransformationPod( + transformationPodName, + transformedEventType, + transformedEventSource, + []byte(transformedBody), + ) client.CreatePodOrFail(transformationPod, lib.WithService(transformationPodName)) // create trigger1 for event transformation client.CreateTriggerOrFailV1Beta1( - triggerName1, + originalTriggerName, resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource1, eventType1, nil), + resources.WithAttributesTriggerFilterV1Beta1(eventSource, eventType, nil), resources.WithSubscriberServiceRefForTriggerV1Beta1(transformationPodName), ) // create logger pod and service - loggerPod := resources.EventLoggerPod(loggerPodName) - client.CreatePodOrFail(loggerPod, lib.WithService(loggerPodName)) + eventTracker, _ := recordevents.StartEventRecordOrFail(client, recordEventsPodName) + defer eventTracker.Cleanup() // create trigger2 for event receiving client.CreateTriggerOrFailV1Beta1( - triggerName2, + transformedTriggerName, resources.WithBrokerV1Beta1(brokerName), - resources.WithAttributesTriggerFilterV1Beta1(eventSource2, eventType2, nil), - resources.WithSubscriberServiceRefForTriggerV1Beta1(loggerPodName), + resources.WithAttributesTriggerFilterV1Beta1(transformedEventSource, transformedEventType, nil), + resources.WithSubscriberServiceRefForTriggerV1Beta1(recordEventsPodName), ) // wait for all test resources to be ready, so that we can start sending events client.WaitForAllTestResourcesReadyOrFail() - // send fake CloudEvent to the broker - eventToSend := cloudevents.New( - fmt.Sprintf(`{"msg":%q}`, eventBody), - cloudevents.WithSource(eventSource1), - cloudevents.WithType(eventType1), - ) - client.SendFakeEventToAddressableOrFail(senderName, brokerName, lib.BrokerTypeMeta, eventToSend) + // eventToSend is the event sent as input of the test + eventToSend := cloudevents.NewEvent() + eventToSend.SetID(uuid.New().String()) + eventToSend.SetType(eventType) + eventToSend.SetSource(eventSource) + if err := eventToSend.SetData(cloudevents.ApplicationJSON, []byte(eventBody)); err != nil { + t.Fatalf("Cannot set the payload of the event: %s", err.Error()) + } + client.SendEventToAddressable(senderName, brokerName, lib.BrokerTypeMeta, eventToSend) // check if the logging service receives the correct event - if err := client.CheckLog(loggerPodName, lib.CheckerContains(transformedEventBody)); err != nil { - st.Fatalf("String %q not found in logs of logger pod %q: %v", transformedEventBody, loggerPodName, err) - } + eventTracker.AssertAtLeast(1, recordevents.MatchEvent( + HasSource(transformedEventSource), + HasType(transformedEventType), + HasData([]byte(transformedBody)), + )) + + eventTracker.AssertNot(recordevents.MatchEvent( + HasSource(eventSource), + HasType(eventType), + HasData([]byte(eventBody)), + )) }) } diff --git a/test/e2e/helpers/broker_test_helper.go b/test/e2e/helpers/broker_test_helper.go index 83a75e0af8b..dcfd7b2409c 100644 --- a/test/e2e/helpers/broker_test_helper.go +++ b/test/e2e/helpers/broker_test_helper.go @@ -36,23 +36,6 @@ import ( "knative.dev/eventing/test/lib/resources" ) -const ( - any = v1beta1.TriggerAnyFilter - eventType1 = "type1" - eventType2 = "type2" - eventSource1 = "http://source1.com" - eventSource2 = "http://source2.com" - // Be careful with the length of extension name and values, - // we use extension name and value as a part of the name of resources like subscriber and trigger, - // the maximum characters allowed of resource name is 63 - extensionName1 = "extname1" - extensionValue1 = "extval1" - extensionName2 = "extname2" - extensionValue2 = "extvalue2" - nonMatchingExtensionName = "nonmatchingextname" - nonMatchingExtensionValue = "nonmatchingextval" -) - type eventTestCase struct { Type string Source string @@ -65,10 +48,10 @@ func (tc eventTestCase) String() string { eventSource := tc.Source extensions := tc.Extensions // Pod names need to be lowercase. We might have an eventType as Any, that is why we lowercase them. - if eventType == any { + if eventType == v1beta1.TriggerAnyFilter { eventType = "testany" } - if eventSource == any { + if eventSource == v1beta1.TriggerAnyFilter { eventSource = "testany" } else { u, _ := url.Parse(eventSource) @@ -84,20 +67,20 @@ func (tc eventTestCase) String() string { // ToEventMatcher converts the test case to the event matcher func (tc eventTestCase) ToEventMatcher() cetest.EventMatcher { var matchers []cetest.EventMatcher - if tc.Type == any { + if tc.Type == v1beta1.TriggerAnyFilter { matchers = append(matchers, cetest.ContainsAttributes(spec.Type)) } else { matchers = append(matchers, cetest.HasType(tc.Type)) } - if tc.Source == any { + if tc.Source == v1beta1.TriggerAnyFilter { matchers = append(matchers, cetest.ContainsAttributes(spec.Source)) } else { matchers = append(matchers, cetest.HasSource(tc.Source)) } for k, v := range tc.Extensions { - if v == any { + if v == v1beta1.TriggerAnyFilter { matchers = append(matchers, cetest.ContainsExtensions(k)) } else { matchers = append(matchers, cetest.HasExtension(k, v)) @@ -134,6 +117,22 @@ func ChannelBasedBrokerCreator(channel metav1.TypeMeta, brokerClass string) Brok // different events to the broker's address. // Finally, it verifies that only the appropriate events are routed to the subscribers. func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shouldLabelNamespace bool) { + const ( + any = v1beta1.TriggerAnyFilter + eventType1 = "type1" + eventType2 = "type2" + eventSource1 = "http://source1.com" + eventSource2 = "http://source2.com" + // Be careful with the length of extension name and values, + // we use extension name and value as a part of the name of resources like subscriber and trigger, + // the maximum characters allowed of resource name is 63 + extensionName1 = "extname1" + extensionValue1 = "extval1" + extensionName2 = "extname2" + extensionValue2 = "extvalue2" + nonMatchingExtensionName = "nonmatchingextname" + nonMatchingExtensionValue = "nonmatchingextval" + ) tests := []struct { name string // These are the event context attributes and extension attributes that will be send. @@ -359,7 +358,7 @@ func extensionsToString(extensions map[string]interface{}) string { sb.WriteString(sortedExtensionName) sb.WriteString("-") vStr := fmt.Sprintf("%v", extensions[sortedExtensionName]) - if vStr == any { + if vStr == v1beta1.TriggerAnyFilter { vStr = "testany" } sb.WriteString(vStr) diff --git a/test/e2e/helpers/trigger_no_broker_test_helper.go b/test/e2e/helpers/trigger_no_broker_test_helper.go index 60a23faaaeb..8bb9e266979 100644 --- a/test/e2e/helpers/trigger_no_broker_test_helper.go +++ b/test/e2e/helpers/trigger_no_broker_test_helper.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "knative.dev/eventing/test/lib" + "knative.dev/eventing/test/lib/recordevents" "knative.dev/eventing/test/lib/resources" ) @@ -35,9 +36,11 @@ func TestTriggerNoBroker(t *testing.T, channel string, brokerCreator BrokerCreat client := lib.Setup(t, true) defer lib.TearDown(client) brokerName := strings.ToLower(channel) + subscriberName := "dumper-empty" - pod := resources.EventLoggerPod(subscriberName) - client.CreatePodOrFail(pod, lib.WithService(subscriberName)) + eventTracker, _ := recordevents.StartEventRecordOrFail(client, subscriberName) + defer eventTracker.Cleanup() + client.CreateTriggerOrFailV1Beta1("testtrigger", resources.WithSubscriberServiceRefForTriggerV1Beta1(subscriberName), resources.WithBrokerV1Beta1(brokerName),