From e9133e3bd7c7833b9277ccfeb7b49d355d86b77b Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Wed, 10 Jun 2020 10:13:20 +0200 Subject: [PATCH 01/10] Introduce sources e2e flag --- test/e2e_flags.go | 65 +++++++++--------------------- test/flags/channels.go | 42 +++++++++++++++++++ test/flags/eventing_environment.go | 9 +++++ test/flags/sources.go | 42 +++++++++++++++++++ 4 files changed, 111 insertions(+), 47 deletions(-) create mode 100644 test/flags/channels.go create mode 100644 test/flags/eventing_environment.go create mode 100644 test/flags/sources.go diff --git a/test/e2e_flags.go b/test/e2e_flags.go index 9397a67d5b2..b27841ee9dd 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -21,63 +21,34 @@ package test import ( "flag" - "fmt" - "log" - "strings" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + testFlags "knative.dev/eventing/test/flags" "knative.dev/eventing/test/lib" + "log" ) +const ( + ChannelUsage = "The names of the channel type metas, separated by comma. " + + "Example: \"messaging.knative.dev/v1alpha1:InMemoryChannel," + + "messaging.cloud.google.com/v1alpha1:Channel,messaging.knative.dev/v1alpha1:KafkaChannel\"." + BrokerUsage = "Which brokerclass to test, requires the proper Broker " + + "implementation to have been installed, and only one value. brokerclass " + + "must be (for now) 'MTChannelBasedBroker'." + SourceUsage = "The names of the source type metas, separated by comma. " + + "Example: \"sources.knative.dev/v1alpha1:ApiServerSource," + + "sources.knative.dev/v1alpha1:PingSource\"." +) // EventingFlags holds the command line flags specific to knative/eventing. //var EventingFlags *EventingEnvironmentFlags -var EventingFlags EventingEnvironmentFlags - -// Channels holds the Channels we want to run test against. -type Channels []metav1.TypeMeta - -func (channels *Channels) String() string { - return fmt.Sprint(*channels) -} - -// Set converts the input string to Channels. -// The default Channel we will test against is InMemoryChannel. -func (channels *Channels) Set(value string) error { - for _, channel := range strings.Split(value, ",") { - channel := strings.TrimSpace(channel) - split := strings.Split(channel, ":") - if len(split) != 2 { - log.Fatalf("The given Channel name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", channel) - } - tm := metav1.TypeMeta{ - APIVersion: split[0], - Kind: split[1], - } - if !isValid(tm.Kind) { - log.Fatalf("The given channel name %q is invalid, tests cannot be run.\n", channel) - } - - *channels = append(*channels, tm) - } - return nil -} - -// Check if the channel name is valid. -func isValid(channel string) bool { - return strings.HasSuffix(channel, "Channel") -} - -// EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo. -type EventingEnvironmentFlags struct { - BrokerClass string - Channels -} +var EventingFlags testFlags.EventingEnvironmentFlags // InitializeEventingFlags registers flags used by e2e tests, calling flag.Parse() here would fail in // go1.13+, see https://github.com/knative/test-infra/issues/1329 for details func InitializeEventingFlags() { - flag.Var(&EventingFlags.Channels, "channels", "The names of the channel type metas, separated by comma. Example: \"messaging.knative.dev/v1alpha1:InMemoryChannel,messaging.cloud.google.com/v1alpha1:Channel,messaging.knative.dev/v1alpha1:KafkaChannel\".") - flag.StringVar(&EventingFlags.BrokerClass, "brokerclass", "MTChannelBasedBroker", "Which brokerclass to test, requires the proper Broker implementation to have been installed, and only one value. brokerclass must be (for now) 'MTChannelBasedBroker'.") + + flag.Var(&EventingFlags.Channels, "channels", ChannelUsage) + flag.StringVar(&EventingFlags.BrokerClass, "brokerclass", "MTChannelBasedBroker", BrokerUsage) + flag.Var(&EventingFlags.Sources, "sources", SourceUsage) flag.Parse() // If no channel is passed through the flag, initialize it as the DefaultChannel. diff --git a/test/flags/channels.go b/test/flags/channels.go new file mode 100644 index 00000000000..f29c345efac --- /dev/null +++ b/test/flags/channels.go @@ -0,0 +1,42 @@ +package flags + +import ( + "fmt" + "log" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Channels holds the Channels we want to run test against. +type Channels []metav1.TypeMeta + +func (channels *Channels) String() string { + return fmt.Sprint(*channels) +} + +// Set converts the input string to Channels. +func (channels *Channels) Set(value string) error { + for _, channel := range strings.Split(value, ",") { + channel := strings.TrimSpace(channel) + split := strings.Split(channel, ":") + if len(split) != 2 { + log.Fatalf("The given Channel name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", channel) + } + tm := metav1.TypeMeta{ + APIVersion: split[0], + Kind: split[1], + } + if !isValidChannel(tm.Kind) { + log.Fatalf("The given channel name %q is invalid, tests cannot be run.\n", channel) + } + + *channels = append(*channels, tm) + } + return nil +} + +// Check if the channel name is valid. +func isValidChannel(channel string) bool { + return strings.HasSuffix(channel, "Channel") +} diff --git a/test/flags/eventing_environment.go b/test/flags/eventing_environment.go new file mode 100644 index 00000000000..57ce3e3de74 --- /dev/null +++ b/test/flags/eventing_environment.go @@ -0,0 +1,9 @@ +package flags + + +// EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo. +type EventingEnvironmentFlags struct { + BrokerClass string + Channels + Sources +} diff --git a/test/flags/sources.go b/test/flags/sources.go new file mode 100644 index 00000000000..633b7a6ba38 --- /dev/null +++ b/test/flags/sources.go @@ -0,0 +1,42 @@ +package flags + +import ( + "fmt" + "log" + "strings" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Sources holds the Sourcess we want to run test against. +type Sources []metav1.TypeMeta + +func (sources *Sources) String() string { + return fmt.Sprint(*sources) +} + +// Set converts the input string to Sources. +func (sources *Sources) Set(value string) error { + for _, source := range strings.Split(value, ",") { + source := strings.TrimSpace(source) + split := strings.Split(source, ":") + if len(split) != 2 { + log.Fatalf("The given Source name %q is invalid, it needs to be in the form \"apiVersion:Kind\".", source) + } + tm := metav1.TypeMeta{ + APIVersion: split[0], + Kind: split[1], + } + if !isValidSource(tm.Kind) { + log.Fatalf("The given source name %q is invalid, tests cannot be run.\n", source) + } + + *sources = append(*sources, tm) + } + return nil +} + +// Check if the Source name is valid. +func isValidSource(source string) bool { + return strings.HasSuffix(source, "Source") +} From 6c310eef9245b4b7378d5e750878c9662a1997b0 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Sat, 13 Jun 2020 22:50:17 +0200 Subject: [PATCH 02/10] Refactor ChannelTestRunner to ComponentTestRunner --- .../broker_control_plane_test_helper.go | 2 +- .../helpers/broker_tracing_test_helper.go | 4 +-- ...sable_resolver_cluster_role_test_helper.go | 2 +- ...le_manipulator_cluster_role_test_helper.go | 2 +- .../channel_crd_metadata_test_helper.go | 4 +-- .../helpers/channel_crd_name_test_helper.go | 4 +-- .../channel_header_single_event_helper.go | 2 +- .../helpers/channel_spec_test_helper.go | 2 +- .../channel_status_subscriber_test_helper.go | 4 +-- .../helpers/channel_status_test_helper.go | 4 +-- .../helpers/channel_tracing_test_helper.go | 4 +-- test/conformance/main_test.go | 12 +++++--- .../e2e/helpers/broker_channel_flow_helper.go | 2 +- ...broker_event_transformation_test_helper.go | 2 +- test/e2e/helpers/channel_chain_test_helper.go | 2 +- .../helpers/channel_defaulter_test_helper.go | 4 +-- test/e2e/helpers/channel_dls_test_helper.go | 2 +- ...channel_event_tranformation_test_helper.go | 2 +- .../helpers/channel_single_event_helper.go | 2 +- test/e2e/helpers/parallel_test_helper.go | 2 +- test/e2e/helpers/sequence_test_helper.go | 2 +- test/e2e/main_test.go | 8 +++--- test/lib/config.go | 2 +- test/lib/test_runner.go | 28 +++++++++---------- test/upgrade/main_test.go | 8 +++--- 25 files changed, 58 insertions(+), 54 deletions(-) diff --git a/test/conformance/helpers/broker_control_plane_test_helper.go b/test/conformance/helpers/broker_control_plane_test_helper.go index c7791de1af8..2a606e1e244 100644 --- a/test/conformance/helpers/broker_control_plane_test_helper.go +++ b/test/conformance/helpers/broker_control_plane_test_helper.go @@ -39,7 +39,7 @@ import ( func BrokerV1Beta1ControlPlaneTestHelperWithChannelTestRunner( t *testing.T, brokerClass string, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, setupClient ...lib.SetupClientOption, ) { channelTestRunner.RunTests(t, lib.FeatureBasic, func(t *testing.T, channel metav1.TypeMeta) { diff --git a/test/conformance/helpers/broker_tracing_test_helper.go b/test/conformance/helpers/broker_tracing_test_helper.go index f034c3ce576..31b51931ee3 100644 --- a/test/conformance/helpers/broker_tracing_test_helper.go +++ b/test/conformance/helpers/broker_tracing_test_helper.go @@ -37,11 +37,11 @@ import ( ) // BrokerTracingTestHelperWithChannelTestRunner runs the Broker tracing tests for all Channels in -// the ChannelTestRunner. +// the ComponentsTestRunner. func BrokerTracingTestHelperWithChannelTestRunner( t *testing.T, brokerClass string, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, setupClient lib.SetupClientOption, ) { channelTestRunner.RunTests(t, lib.FeatureBasic, func(t *testing.T, channel metav1.TypeMeta) { diff --git a/test/conformance/helpers/channel_addressable_resolver_cluster_role_test_helper.go b/test/conformance/helpers/channel_addressable_resolver_cluster_role_test_helper.go index d1edc7b14fa..c78210d6964 100644 --- a/test/conformance/helpers/channel_addressable_resolver_cluster_role_test_helper.go +++ b/test/conformance/helpers/channel_addressable_resolver_cluster_role_test_helper.go @@ -30,7 +30,7 @@ import ( func TestChannelAddressableResolverClusterRoleTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_channelable_manipulator_cluster_role_test_helper.go b/test/conformance/helpers/channel_channelable_manipulator_cluster_role_test_helper.go index ded9976d310..b9b56e0c678 100644 --- a/test/conformance/helpers/channel_channelable_manipulator_cluster_role_test_helper.go +++ b/test/conformance/helpers/channel_channelable_manipulator_cluster_role_test_helper.go @@ -30,7 +30,7 @@ import ( func TestChannelChannelableManipulatorClusterRoleTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_crd_metadata_test_helper.go b/test/conformance/helpers/channel_crd_metadata_test_helper.go index e3bcfca0ed8..b9bbf6fdba4 100644 --- a/test/conformance/helpers/channel_crd_metadata_test_helper.go +++ b/test/conformance/helpers/channel_crd_metadata_test_helper.go @@ -26,10 +26,10 @@ import ( ) // ChannelCRDMetadataTestHelperWithChannelTestRunner runs the Channel CRD metadata tests for all -// Channel resources in the ChannelTestRunner. +// Channel resources in the ComponentsTestRunner. func ChannelCRDMetadataTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_crd_name_test_helper.go b/test/conformance/helpers/channel_crd_name_test_helper.go index ad7af89c435..3d9bff287ee 100644 --- a/test/conformance/helpers/channel_crd_name_test_helper.go +++ b/test/conformance/helpers/channel_crd_name_test_helper.go @@ -30,10 +30,10 @@ const ( ) // ChannelCRDNameTestHelperWithChannelTestRunner runs the Channel CRD name tests for all -// Channel resources in the ChannelTestRunner. +// Channel resources in the ComponentsTestRunner. func ChannelCRDNameTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_header_single_event_helper.go b/test/conformance/helpers/channel_header_single_event_helper.go index 3a7d0e871dd..861a0158fd4 100644 --- a/test/conformance/helpers/channel_header_single_event_helper.go +++ b/test/conformance/helpers/channel_header_single_event_helper.go @@ -37,7 +37,7 @@ EventSource ---> Channel ---> Subscription ---> Service(Logger) // SingleEventHelperForChannelTestHelper is the helper function for header_test func SingleEventHelperForChannelTestHelper(t *testing.T, encoding string, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { channelName := "conformance-headers-channel-" + encoding diff --git a/test/conformance/helpers/channel_spec_test_helper.go b/test/conformance/helpers/channel_spec_test_helper.go index 0e3c4928be7..125f9ecb9a6 100644 --- a/test/conformance/helpers/channel_spec_test_helper.go +++ b/test/conformance/helpers/channel_spec_test_helper.go @@ -34,7 +34,7 @@ import ( func ChannelSpecTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_status_subscriber_test_helper.go b/test/conformance/helpers/channel_status_subscriber_test_helper.go index 0e982c8c6f5..aacbae85675 100644 --- a/test/conformance/helpers/channel_status_subscriber_test_helper.go +++ b/test/conformance/helpers/channel_status_subscriber_test_helper.go @@ -29,10 +29,10 @@ import ( ) // ChannelStatusSubscriberTestHelperWithChannelTestRunner runs the tests of -// subscriber field of status for all Channels in the ChannelTestRunner. +// subscriber field of status for all Channels in the ComponentsTestRunner. func ChannelStatusSubscriberTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_status_test_helper.go b/test/conformance/helpers/channel_status_test_helper.go index a40cf3c75b7..3bc97830d07 100644 --- a/test/conformance/helpers/channel_status_test_helper.go +++ b/test/conformance/helpers/channel_status_test_helper.go @@ -25,10 +25,10 @@ import ( ) // ChannelStatusTestHelperWithChannelTestRunner runs the Channel status tests for all Channels in -// the ChannelTestRunner. +// the ComponentsTestRunner. func ChannelStatusTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { diff --git a/test/conformance/helpers/channel_tracing_test_helper.go b/test/conformance/helpers/channel_tracing_test_helper.go index 9d9c3380be2..2ae0a36065c 100644 --- a/test/conformance/helpers/channel_tracing_test_helper.go +++ b/test/conformance/helpers/channel_tracing_test_helper.go @@ -61,10 +61,10 @@ type TracingTestCase struct { } // ChannelTracingTestHelperWithChannelTestRunner runs the Channel tracing tests for all Channels in -// the ChannelTestRunner. +// the ComponentsTestRunner. func ChannelTracingTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, setupClient lib.SetupClientOption, ) { channelTestRunner.RunTests(t, lib.FeatureBasic, func(t *testing.T, channel metav1.TypeMeta) { diff --git a/test/conformance/main_test.go b/test/conformance/main_test.go index 1041e4dd573..17fdbfb65c0 100644 --- a/test/conformance/main_test.go +++ b/test/conformance/main_test.go @@ -26,15 +26,19 @@ import ( "knative.dev/eventing/test/lib" ) -var channelTestRunner lib.ChannelTestRunner +var channelTestRunner lib.ComponentsTestRunner +var sourcesTestRunner lib.ComponentsTestRunner var brokerClass string func TestMain(m *testing.M) { os.Exit(func() int { test.InitializeEventingFlags() - channelTestRunner = lib.ChannelTestRunner{ - ChannelFeatureMap: lib.ChannelFeatureMap, - ChannelsToTest: test.EventingFlags.Channels, + channelTestRunner = lib.ComponentsTestRunner{ + ComponentFeatureMap: lib.ChannelFeatureMap, + ComponentsToTest: test.EventingFlags.Channels, + } + sourcesTestRunner = lib.ComponentsTestRunner{ + ComponentsToTest: test.EventingFlags.Sources, } brokerClass = test.EventingFlags.BrokerClass diff --git a/test/e2e/helpers/broker_channel_flow_helper.go b/test/e2e/helpers/broker_channel_flow_helper.go index 7dcb97135b3..2465086f9da 100644 --- a/test/e2e/helpers/broker_channel_flow_helper.go +++ b/test/e2e/helpers/broker_channel_flow_helper.go @@ -51,7 +51,7 @@ Trigger3 filters the transformed event and sends it to Channel. */ func BrokerChannelFlowWithTransformation(t *testing.T, brokerClass string, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( senderName = "e2e-brokerchannel-sender" diff --git a/test/e2e/helpers/broker_event_transformation_test_helper.go b/test/e2e/helpers/broker_event_transformation_test_helper.go index 413a1ec9f5d..0f2fdb1f1d7 100644 --- a/test/e2e/helpers/broker_event_transformation_test_helper.go +++ b/test/e2e/helpers/broker_event_transformation_test_helper.go @@ -45,7 +45,7 @@ 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, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( senderName = "e2e-eventtransformation-sender" diff --git a/test/e2e/helpers/channel_chain_test_helper.go b/test/e2e/helpers/channel_chain_test_helper.go index 7553dbdda87..db6b2ce5ac6 100644 --- a/test/e2e/helpers/channel_chain_test_helper.go +++ b/test/e2e/helpers/channel_chain_test_helper.go @@ -32,7 +32,7 @@ import ( // ChannelChainTestHelper is the helper function for channel_chain_test func ChannelChainTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( senderName = "e2e-channelchain-sender" diff --git a/test/e2e/helpers/channel_defaulter_test_helper.go b/test/e2e/helpers/channel_defaulter_test_helper.go index a2c1baace4a..62a5fb45782 100644 --- a/test/e2e/helpers/channel_defaulter_test_helper.go +++ b/test/e2e/helpers/channel_defaulter_test_helper.go @@ -50,7 +50,7 @@ const ( // ChannelClusterDefaulterTestHelper is the helper function for channel_defaulter_test func ChannelClusterDefaulterTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { // these tests cannot be run in parallel as they have cluster-wide impact @@ -69,7 +69,7 @@ func ChannelClusterDefaulterTestHelper(t *testing.T, // ChannelNamespaceDefaulterTestHelper is the helper function for channel_defaulter_test func ChannelNamespaceDefaulterTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { channelTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) { // we cannot run these tests in parallel as the updateDefaultChannelCM function is not thread-safe diff --git a/test/e2e/helpers/channel_dls_test_helper.go b/test/e2e/helpers/channel_dls_test_helper.go index 8bab0d67f60..15eb8ae59cd 100644 --- a/test/e2e/helpers/channel_dls_test_helper.go +++ b/test/e2e/helpers/channel_dls_test_helper.go @@ -32,7 +32,7 @@ import ( // ChannelDeadLetterSinkTestHelper is the helper function for channel_deadlettersink_test func ChannelDeadLetterSinkTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( senderName = "e2e-channelchain-sender" diff --git a/test/e2e/helpers/channel_event_tranformation_test_helper.go b/test/e2e/helpers/channel_event_tranformation_test_helper.go index 7bdacccc650..710033b0308 100644 --- a/test/e2e/helpers/channel_event_tranformation_test_helper.go +++ b/test/e2e/helpers/channel_event_tranformation_test_helper.go @@ -32,7 +32,7 @@ import ( // EventTransformationForSubscriptionTestHelper is the helper function for channel_event_tranformation_test func EventTransformationForSubscriptionTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { senderName := "e2e-eventtransformation-sender" channelNames := []string{"e2e-eventtransformation1", "e2e-eventtransformation2"} diff --git a/test/e2e/helpers/channel_single_event_helper.go b/test/e2e/helpers/channel_single_event_helper.go index f82b9ec8473..6a0d2134373 100644 --- a/test/e2e/helpers/channel_single_event_helper.go +++ b/test/e2e/helpers/channel_single_event_helper.go @@ -46,7 +46,7 @@ const ( func SingleEventForChannelTestHelper(t *testing.T, encoding cloudevents.Encoding, subscriptionVersion SubscriptionVersion, channelVersion string, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { channelName := "e2e-singleevent-channel-" + encoding.String() senderName := "e2e-singleevent-sender-" + encoding.String() diff --git a/test/e2e/helpers/parallel_test_helper.go b/test/e2e/helpers/parallel_test_helper.go index 8b8e881ffcc..4507b19b2fb 100644 --- a/test/e2e/helpers/parallel_test_helper.go +++ b/test/e2e/helpers/parallel_test_helper.go @@ -38,7 +38,7 @@ type branchConfig struct { } func ParallelTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( senderPodName = "e2e-parallel" diff --git a/test/e2e/helpers/sequence_test_helper.go b/test/e2e/helpers/sequence_test_helper.go index 40103604636..b288a3e33be 100644 --- a/test/e2e/helpers/sequence_test_helper.go +++ b/test/e2e/helpers/sequence_test_helper.go @@ -34,7 +34,7 @@ import ( ) func SequenceTestHelper(t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption) { const ( sequenceName = "e2e-sequence" diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go index 5bb96e9faae..ec266187a9f 100644 --- a/test/e2e/main_test.go +++ b/test/e2e/main_test.go @@ -25,14 +25,14 @@ import ( var setup = lib.Setup var tearDown = lib.TearDown -var channelTestRunner lib.ChannelTestRunner +var channelTestRunner lib.ComponentsTestRunner var brokerClass string func TestMain(m *testing.M) { test.InitializeEventingFlags() - channelTestRunner = lib.ChannelTestRunner{ - ChannelFeatureMap: lib.ChannelFeatureMap, - ChannelsToTest: test.EventingFlags.Channels, + channelTestRunner = lib.ComponentsTestRunner{ + ComponentFeatureMap: lib.ChannelFeatureMap, + ComponentsToTest: test.EventingFlags.Channels, } brokerClass = test.EventingFlags.BrokerClass os.Exit(m.Run()) diff --git a/test/lib/config.go b/test/lib/config.go index c1c560e0257..4c4c9490b60 100644 --- a/test/lib/config.go +++ b/test/lib/config.go @@ -37,7 +37,7 @@ var MessagingChannelTypeMeta = metav1.TypeMeta{ Kind: resources.ChannelKind, } -// ChannelFeatureMap saves the channel-features mapping. +// ComponentFeatureMap saves the channel-features mapping. // Each pair means the channel support the list of features. var ChannelFeatureMap = map[metav1.TypeMeta][]Feature{ InMemoryChannelTypeMeta: {FeatureBasic}, diff --git a/test/lib/test_runner.go b/test/lib/test_runner.go index edbcf7d1fb6..7fd86ed0f5d 100644 --- a/test/lib/test_runner.go +++ b/test/lib/test_runner.go @@ -45,29 +45,29 @@ const ( testPullSecretName = "kn-eventing-test-pull-secret" ) -// ChannelTestRunner is used to run tests against channels. -type ChannelTestRunner struct { - ChannelFeatureMap map[metav1.TypeMeta][]Feature - ChannelsToTest []metav1.TypeMeta +// ComponentsTestRunner is used to run tests against different eventing components. +type ComponentsTestRunner struct { + ComponentFeatureMap map[metav1.TypeMeta][]Feature + ComponentsToTest []metav1.TypeMeta } -// RunTests will use all channels that support the given feature, to run +// RunTests will use all components that support the given feature, to run // a test for the testFunc. -func (tr *ChannelTestRunner) RunTests( +func (tr *ComponentsTestRunner) RunTests( t *testing.T, feature Feature, - testFunc func(st *testing.T, channel metav1.TypeMeta), + testFunc func(st *testing.T, component metav1.TypeMeta), ) { t.Parallel() - for _, channel := range tr.ChannelsToTest { - // If a Channel is not present in the map, then assume it has all properties. This is so an - // unknown Channel can be specified via the --channel flag and have tests run. - // TODO Use a flag to specify the features of the flag based Channel, rather than assuming + for _, component := range tr.ComponentsToTest { + // If a component is not present in the map, then assume it has all properties. This is so an + // unknown component (e.g. a Channel) can be specified via a dedicated flag (e.g. --channels) and have tests run. + // TODO Use a flag to specify the features of the flag based component, rather than assuming // it supports all features. - features, present := tr.ChannelFeatureMap[channel] + features, present := tr.ComponentFeatureMap[component] if !present || contains(features, feature) { - t.Run(fmt.Sprintf("%s-%s", channel.Kind, channel.APIVersion), func(st *testing.T) { - testFunc(st, channel) + t.Run(fmt.Sprintf("%s-%s", component.Kind, component.APIVersion), func(st *testing.T) { + testFunc(st, component) }) } } diff --git a/test/upgrade/main_test.go b/test/upgrade/main_test.go index 9990630cb1a..cbbaa9dcc8a 100644 --- a/test/upgrade/main_test.go +++ b/test/upgrade/main_test.go @@ -25,13 +25,13 @@ import ( var setup = lib.Setup var tearDown = lib.TearDown -var channelTestRunner lib.ChannelTestRunner +var channelTestRunner lib.ComponentsTestRunner func TestMain(m *testing.M) { test.InitializeEventingFlags() - channelTestRunner = lib.ChannelTestRunner{ - ChannelFeatureMap: lib.ChannelFeatureMap, - ChannelsToTest: test.EventingFlags.Channels, + channelTestRunner = lib.ComponentsTestRunner{ + ComponentFeatureMap: lib.ChannelFeatureMap, + ComponentsToTest: test.EventingFlags.Channels, } os.Exit(m.Run()) } From 15cafa9791521b604fe8b52036254351d8a5b9a9 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Sat, 13 Jun 2020 23:00:32 +0200 Subject: [PATCH 03/10] Add source labels conformance test --- .../source_crd_metadata_test_helper.go | 44 +++++++++++++++++++ test/conformance/source_crd_metadata_test.go | 12 +++++ 2 files changed, 56 insertions(+) create mode 100644 test/conformance/helpers/source_crd_metadata_test_helper.go create mode 100644 test/conformance/source_crd_metadata_test.go diff --git a/test/conformance/helpers/source_crd_metadata_test_helper.go b/test/conformance/helpers/source_crd_metadata_test_helper.go new file mode 100644 index 00000000000..2cb67fdb430 --- /dev/null +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -0,0 +1,44 @@ +package helpers + +import ( + "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/test/lib" + "testing" +) + +func SourceCRDMetadataTestHelperWithChannelTestRunner( + t *testing.T, + sourceTestRunner lib.ComponentsTestRunner, + options ...lib.SetupClientOption, +) { + + sourceTestRunner.RunTests(t, lib.FeatureBasic, func(st *testing.T, source metav1.TypeMeta) { + client := lib.Setup(st, true, options...) + defer lib.TearDown(client) + + t.Run("Source CRD has required label", func(t *testing.T) { + sourceCRDHasRequiredLabels(st, client, source) + }) + + }) +} + +func sourceCRDHasRequiredLabels(st *testing.T, client *lib.Client, source metav1.TypeMeta) { + // From spec: + // Each source MUST have the following: + // label of duck.knative.dev/source: "true" + + gvr, _ := meta.UnsafeGuessKindToResource(source.GroupVersionKind()) + crdName := gvr.Resource + "." + gvr.Group + + crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ + TypeMeta: metav1.TypeMeta{}, + }) + if err != nil { + client.T.Fatalf("Unable to find CRD for %q: %v", source, err) + } + if crd.Labels["duck.knative.dev/source"] != "true" { + client.T.Fatalf("Source CRD doesn't have the label 'duck.knative.dev/source=true' %q: %v", source, err) + } +} diff --git a/test/conformance/source_crd_metadata_test.go b/test/conformance/source_crd_metadata_test.go new file mode 100644 index 00000000000..3054d2fceae --- /dev/null +++ b/test/conformance/source_crd_metadata_test.go @@ -0,0 +1,12 @@ +package conformance + +import ( + "knative.dev/eventing/test/conformance/helpers" + "knative.dev/eventing/test/lib" + "testing" +) + +func TestSourceCRDMetadata(t *testing.T) { + helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, lib.SetupClientOptionNoop) +} + From 1cd560188893ece0ad7ead49628427682aa7c15b Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Sun, 14 Jun 2020 10:30:19 +0200 Subject: [PATCH 04/10] Refactor out object labels verification code in conformance tests --- .../channel_crd_metadata_test_helper.go | 32 ++++++++--------- test/conformance/helpers/metadata.go | 36 +++++++++++++++++++ .../source_crd_metadata_test_helper.go | 34 +++++++----------- test/conformance/source_crd_metadata_test.go | 17 ++++++++- test/e2e_flags.go | 5 +-- test/flags/channels.go | 16 +++++++++ test/flags/eventing_environment.go | 17 ++++++++- test/flags/sources.go | 16 +++++++++ 8 files changed, 130 insertions(+), 43 deletions(-) create mode 100644 test/conformance/helpers/metadata.go diff --git a/test/conformance/helpers/channel_crd_metadata_test_helper.go b/test/conformance/helpers/channel_crd_metadata_test_helper.go index b9bbf6fdba4..f1db0ee5e27 100644 --- a/test/conformance/helpers/channel_crd_metadata_test_helper.go +++ b/test/conformance/helpers/channel_crd_metadata_test_helper.go @@ -25,6 +25,11 @@ import ( "knative.dev/eventing/test/lib" ) +var channelLabels = map[string]string{ + "messaging.knative.dev/subscribable": "true", + "duck.knative.dev/addressable": "true", +} + // ChannelCRDMetadataTestHelperWithChannelTestRunner runs the Channel CRD metadata tests for all // Channel resources in the ComponentsTestRunner. func ChannelCRDMetadataTestHelperWithChannelTestRunner( @@ -41,7 +46,7 @@ func ChannelCRDMetadataTestHelperWithChannelTestRunner( channelIsNamespaced(st, client, channel) }) t.Run("Channel CRD has required label", func(t *testing.T) { - channelCRDHasRequiredLabels(st, client, channel) + channelCRDHasRequiredLabels(client, channel) }) t.Run("Channel CRD has required label", func(t *testing.T) { channelCRDHasProperCategory(st, client, channel) @@ -61,26 +66,19 @@ func channelIsNamespaced(st *testing.T, client *lib.Client, channel metav1.TypeM } } -func channelCRDHasRequiredLabels(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { +func channelCRDHasRequiredLabels(client *lib.Client, channel metav1.TypeMeta) { // From spec: // Each channel MUST have the following: // label of messaging.knative.dev/subscribable: "true" // label of duck.knative.dev/addressable: "true" - - gvr, _ := meta.UnsafeGuessKindToResource(channel.GroupVersionKind()) - crdName := gvr.Resource + "." + gvr.Group - - crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ - TypeMeta: metav1.TypeMeta{}, - }) - if err != nil { - client.T.Fatalf("Unable to find CRD for %q: %v", channel, err) - } - if crd.Labels["messaging.knative.dev/subscribable"] != "true" { - client.T.Fatalf("Channel CRD doesn't have the label 'messaging.knative.dev/subscribable=true' %q: %v", channel, err) - } - if crd.Labels["duck.knative.dev/addressable"] != "true" { - client.T.Fatalf("Channel CRD doesn't have the label 'duck.knative.dev/addressable=true' %q: %v", channel, err) + for k, v := range channelLabels { + yes, err := objectHasRequiredLabels(client, channel, k, v) + if err != nil { + client.T.Fatalf("Unable to find CRD for %q: %v", channel, err) + } + if !yes { + client.T.Fatalf("Channel CRD doesn't have the label '%s=%s' %q: %v", k, v, channel, err) + } } } diff --git a/test/conformance/helpers/metadata.go b/test/conformance/helpers/metadata.go new file mode 100644 index 00000000000..d36284b6692 --- /dev/null +++ b/test/conformance/helpers/metadata.go @@ -0,0 +1,36 @@ +/* +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 helpers + +import ( + "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/test/lib" +) + +func objectHasRequiredLabels(client *lib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { + gvr, _ := meta.UnsafeGuessKindToResource(object.GroupVersionKind()) + crdName := gvr.Resource + "." + gvr.Group + + crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ + TypeMeta: metav1.TypeMeta{}, + }) + if err != nil { + return false, err + } + return crd.Labels[key] == value, nil +} diff --git a/test/conformance/helpers/source_crd_metadata_test_helper.go b/test/conformance/helpers/source_crd_metadata_test_helper.go index 2cb67fdb430..fb3a8f48b29 100644 --- a/test/conformance/helpers/source_crd_metadata_test_helper.go +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -1,10 +1,10 @@ package helpers import ( - "k8s.io/apimachinery/pkg/api/meta" + "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/eventing/test/lib" - "testing" ) func SourceCRDMetadataTestHelperWithChannelTestRunner( @@ -17,28 +17,18 @@ func SourceCRDMetadataTestHelperWithChannelTestRunner( client := lib.Setup(st, true, options...) defer lib.TearDown(client) + // From spec: + // Each source MUST have the following: + // label of duck.knative.dev/source: "true" t.Run("Source CRD has required label", func(t *testing.T) { - sourceCRDHasRequiredLabels(st, client, source) + yes, err := objectHasRequiredLabels(client, source, "duck.knative.dev/source", "true") + if err != nil { + client.T.Fatalf("Unable to find CRD for %q: %v", source, err) + } + if !yes { + client.T.Fatalf("Source CRD doesn't have the label 'duck.knative.dev/source=true' %q: %v", source, err) + } }) }) } - -func sourceCRDHasRequiredLabels(st *testing.T, client *lib.Client, source metav1.TypeMeta) { - // From spec: - // Each source MUST have the following: - // label of duck.knative.dev/source: "true" - - gvr, _ := meta.UnsafeGuessKindToResource(source.GroupVersionKind()) - crdName := gvr.Resource + "." + gvr.Group - - crd, err := client.Apiextensions.CustomResourceDefinitions().Get(crdName, metav1.GetOptions{ - TypeMeta: metav1.TypeMeta{}, - }) - if err != nil { - client.T.Fatalf("Unable to find CRD for %q: %v", source, err) - } - if crd.Labels["duck.knative.dev/source"] != "true" { - client.T.Fatalf("Source CRD doesn't have the label 'duck.knative.dev/source=true' %q: %v", source, err) - } -} diff --git a/test/conformance/source_crd_metadata_test.go b/test/conformance/source_crd_metadata_test.go index 3054d2fceae..472d83afb53 100644 --- a/test/conformance/source_crd_metadata_test.go +++ b/test/conformance/source_crd_metadata_test.go @@ -1,3 +1,19 @@ +/* +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 conformance import ( @@ -9,4 +25,3 @@ import ( func TestSourceCRDMetadata(t *testing.T) { helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, lib.SetupClientOptionNoop) } - diff --git a/test/e2e_flags.go b/test/e2e_flags.go index b27841ee9dd..a7bde3f3112 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -31,13 +31,14 @@ const ( ChannelUsage = "The names of the channel type metas, separated by comma. " + "Example: \"messaging.knative.dev/v1alpha1:InMemoryChannel," + "messaging.cloud.google.com/v1alpha1:Channel,messaging.knative.dev/v1alpha1:KafkaChannel\"." - BrokerUsage = "Which brokerclass to test, requires the proper Broker " + + BrokerUsage = "Which brokerclass to test, requires the proper Broker " + "implementation to have been installed, and only one value. brokerclass " + "must be (for now) 'MTChannelBasedBroker'." - SourceUsage = "The names of the source type metas, separated by comma. " + + SourceUsage = "The names of the source type metas, separated by comma. " + "Example: \"sources.knative.dev/v1alpha1:ApiServerSource," + "sources.knative.dev/v1alpha1:PingSource\"." ) + // EventingFlags holds the command line flags specific to knative/eventing. //var EventingFlags *EventingEnvironmentFlags var EventingFlags testFlags.EventingEnvironmentFlags diff --git a/test/flags/channels.go b/test/flags/channels.go index f29c345efac..34d619d1542 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -1,3 +1,19 @@ +/* +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 flags import ( diff --git a/test/flags/eventing_environment.go b/test/flags/eventing_environment.go index 57ce3e3de74..65a05dd7ac4 100644 --- a/test/flags/eventing_environment.go +++ b/test/flags/eventing_environment.go @@ -1,5 +1,20 @@ -package flags +/* +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 flags // EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo. type EventingEnvironmentFlags struct { diff --git a/test/flags/sources.go b/test/flags/sources.go index 633b7a6ba38..6d47f5eb853 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -1,3 +1,19 @@ +/* +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 flags import ( From 6271e51c23ce3e78e790fc6371aa2ecf4a6058b5 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Sun, 14 Jun 2020 10:32:49 +0200 Subject: [PATCH 05/10] Fix missing header in conformance helper test file --- .../helpers/source_crd_metadata_test_helper.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/conformance/helpers/source_crd_metadata_test_helper.go b/test/conformance/helpers/source_crd_metadata_test_helper.go index fb3a8f48b29..c9b22df14b8 100644 --- a/test/conformance/helpers/source_crd_metadata_test_helper.go +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -1,3 +1,19 @@ +/* +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 helpers import ( From 7a4c038c945cb8531330b255c459ab6e63e7c8b3 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 15 Jun 2020 15:47:22 +0200 Subject: [PATCH 06/10] Move object labels check to a shared package and sort imports --- .../helpers/channel_crd_metadata_test_helper.go | 12 +++--------- test/conformance/helpers/metadata.go | 14 +++++++++++++- .../helpers/source_crd_metadata_test_helper.go | 12 +++++------- test/conformance/source_crd_metadata_test.go | 3 ++- test/e2e_flags.go | 3 ++- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/test/conformance/helpers/channel_crd_metadata_test_helper.go b/test/conformance/helpers/channel_crd_metadata_test_helper.go index f1db0ee5e27..f0abc748e97 100644 --- a/test/conformance/helpers/channel_crd_metadata_test_helper.go +++ b/test/conformance/helpers/channel_crd_metadata_test_helper.go @@ -71,15 +71,9 @@ func channelCRDHasRequiredLabels(client *lib.Client, channel metav1.TypeMeta) { // Each channel MUST have the following: // label of messaging.knative.dev/subscribable: "true" // label of duck.knative.dev/addressable: "true" - for k, v := range channelLabels { - yes, err := objectHasRequiredLabels(client, channel, k, v) - if err != nil { - client.T.Fatalf("Unable to find CRD for %q: %v", channel, err) - } - if !yes { - client.T.Fatalf("Channel CRD doesn't have the label '%s=%s' %q: %v", k, v, channel, err) - } - } + + + validateRequiredLabels(client, channel, channelLabels) } func channelCRDHasProperCategory(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { diff --git a/test/conformance/helpers/metadata.go b/test/conformance/helpers/metadata.go index d36284b6692..72b50714061 100644 --- a/test/conformance/helpers/metadata.go +++ b/test/conformance/helpers/metadata.go @@ -22,7 +22,19 @@ import ( "knative.dev/eventing/test/lib" ) -func objectHasRequiredLabels(client *lib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { +func validateRequiredLabels(client *lib.Client, object metav1.TypeMeta, labels map[string]string) { + for k, v := range labels { + yes, err := objectHasRequiredLabel(client, object, k, v) + if err != nil { + client.T.Fatalf("can't find CRD for %q: %v", object, err) + } + if !yes { + client.T.Fatalf("can't find label '%s=%s' in CRD %q", k, v, object) + } + } +} + +func objectHasRequiredLabel(client *lib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { gvr, _ := meta.UnsafeGuessKindToResource(object.GroupVersionKind()) crdName := gvr.Resource + "." + gvr.Group diff --git a/test/conformance/helpers/source_crd_metadata_test_helper.go b/test/conformance/helpers/source_crd_metadata_test_helper.go index c9b22df14b8..75630099d7f 100644 --- a/test/conformance/helpers/source_crd_metadata_test_helper.go +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -23,6 +23,10 @@ import ( "knative.dev/eventing/test/lib" ) +var sourceLabels = map[string]string{ + "duck.knative.dev/source": "true", +} + func SourceCRDMetadataTestHelperWithChannelTestRunner( t *testing.T, sourceTestRunner lib.ComponentsTestRunner, @@ -37,13 +41,7 @@ func SourceCRDMetadataTestHelperWithChannelTestRunner( // Each source MUST have the following: // label of duck.knative.dev/source: "true" t.Run("Source CRD has required label", func(t *testing.T) { - yes, err := objectHasRequiredLabels(client, source, "duck.knative.dev/source", "true") - if err != nil { - client.T.Fatalf("Unable to find CRD for %q: %v", source, err) - } - if !yes { - client.T.Fatalf("Source CRD doesn't have the label 'duck.knative.dev/source=true' %q: %v", source, err) - } + validateRequiredLabels(client, source, sourceLabels) }) }) diff --git a/test/conformance/source_crd_metadata_test.go b/test/conformance/source_crd_metadata_test.go index 472d83afb53..e388911bd03 100644 --- a/test/conformance/source_crd_metadata_test.go +++ b/test/conformance/source_crd_metadata_test.go @@ -17,9 +17,10 @@ limitations under the License. package conformance import ( + "testing" + "knative.dev/eventing/test/conformance/helpers" "knative.dev/eventing/test/lib" - "testing" ) func TestSourceCRDMetadata(t *testing.T) { diff --git a/test/e2e_flags.go b/test/e2e_flags.go index a7bde3f3112..296e513a63e 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -21,10 +21,11 @@ package test import ( "flag" + "log" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" testFlags "knative.dev/eventing/test/flags" "knative.dev/eventing/test/lib" - "log" ) const ( From 040361ecec2315382c67d442d49a73a6e3c95117 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 15 Jun 2020 15:55:18 +0200 Subject: [PATCH 07/10] Remove extra empty line in channel crd metadata conf test --- test/conformance/helpers/channel_crd_metadata_test_helper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/conformance/helpers/channel_crd_metadata_test_helper.go b/test/conformance/helpers/channel_crd_metadata_test_helper.go index f0abc748e97..c4f6b92ea14 100644 --- a/test/conformance/helpers/channel_crd_metadata_test_helper.go +++ b/test/conformance/helpers/channel_crd_metadata_test_helper.go @@ -72,7 +72,6 @@ func channelCRDHasRequiredLabels(client *lib.Client, channel metav1.TypeMeta) { // label of messaging.knative.dev/subscribable: "true" // label of duck.knative.dev/addressable: "true" - validateRequiredLabels(client, channel, channelLabels) } From c3b9953e6993ef5940bbef673993f80b5208efc6 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 15 Jun 2020 18:47:58 +0200 Subject: [PATCH 08/10] Some code cleanup in test after review comments --- test/conformance/helpers/metadata.go | 8 ++++---- test/e2e_flags.go | 5 ++--- test/flags/channels.go | 2 +- test/flags/sources.go | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/test/conformance/helpers/metadata.go b/test/conformance/helpers/metadata.go index 72b50714061..d56282c8b91 100644 --- a/test/conformance/helpers/metadata.go +++ b/test/conformance/helpers/metadata.go @@ -19,14 +19,14 @@ package helpers import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "knative.dev/eventing/test/lib" + testlib "knative.dev/eventing/test/lib" ) -func validateRequiredLabels(client *lib.Client, object metav1.TypeMeta, labels map[string]string) { +func validateRequiredLabels(client *testlib.Client, object metav1.TypeMeta, labels map[string]string) { for k, v := range labels { yes, err := objectHasRequiredLabel(client, object, k, v) if err != nil { - client.T.Fatalf("can't find CRD for %q: %v", object, err) + client.T.Fatalf("error while checking labels for %q: %v", object, err) } if !yes { client.T.Fatalf("can't find label '%s=%s' in CRD %q", k, v, object) @@ -34,7 +34,7 @@ func validateRequiredLabels(client *lib.Client, object metav1.TypeMeta, labels m } } -func objectHasRequiredLabel(client *lib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { +func objectHasRequiredLabel(client *testlib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { gvr, _ := meta.UnsafeGuessKindToResource(object.GroupVersionKind()) crdName := gvr.Resource + "." + gvr.Group diff --git a/test/e2e_flags.go b/test/e2e_flags.go index 296e513a63e..74228eb6a33 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -24,7 +24,7 @@ import ( "log" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - testFlags "knative.dev/eventing/test/flags" + testflags "knative.dev/eventing/test/flags" "knative.dev/eventing/test/lib" ) @@ -41,8 +41,7 @@ const ( ) // EventingFlags holds the command line flags specific to knative/eventing. -//var EventingFlags *EventingEnvironmentFlags -var EventingFlags testFlags.EventingEnvironmentFlags +var EventingFlags testflags.EventingEnvironmentFlags // InitializeEventingFlags registers flags used by e2e tests, calling flag.Parse() here would fail in // go1.13+, see https://github.com/knative/test-infra/issues/1329 for details diff --git a/test/flags/channels.go b/test/flags/channels.go index 34d619d1542..350b607365c 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -44,7 +44,7 @@ func (channels *Channels) Set(value string) error { Kind: split[1], } if !isValidChannel(tm.Kind) { - log.Fatalf("The given channel name %q is invalid, tests cannot be run.\n", channel) + log.Fatalf("The given Channel name %q is invalid, tests cannot be run.\n", channel) } *channels = append(*channels, tm) diff --git a/test/flags/sources.go b/test/flags/sources.go index 6d47f5eb853..fa83be85535 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -44,7 +44,7 @@ func (sources *Sources) Set(value string) error { Kind: split[1], } if !isValidSource(tm.Kind) { - log.Fatalf("The given source name %q is invalid, tests cannot be run.\n", source) + log.Fatalf("The given Source name %q is invalid, tests cannot be run.\n", source) } *sources = append(*sources, tm) From c09a0d3255819505b99de6cdfba47cc0f63b32d2 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 15 Jun 2020 18:51:58 +0200 Subject: [PATCH 09/10] Add more descriptive comments to test flags Set methods --- test/flags/channels.go | 2 +- test/flags/sources.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/flags/channels.go b/test/flags/channels.go index 350b607365c..d4ff2cc22b5 100644 --- a/test/flags/channels.go +++ b/test/flags/channels.go @@ -31,7 +31,7 @@ func (channels *Channels) String() string { return fmt.Sprint(*channels) } -// Set converts the input string to Channels. +// Set appends the input string to Channels. func (channels *Channels) Set(value string) error { for _, channel := range strings.Split(value, ",") { channel := strings.TrimSpace(channel) diff --git a/test/flags/sources.go b/test/flags/sources.go index fa83be85535..cc3e016b4db 100644 --- a/test/flags/sources.go +++ b/test/flags/sources.go @@ -31,7 +31,7 @@ func (sources *Sources) String() string { return fmt.Sprint(*sources) } -// Set converts the input string to Sources. +// Set appends the input string to Sources. func (sources *Sources) Set(value string) error { for _, source := range strings.Split(value, ",") { source := strings.TrimSpace(source) From 0c4f1165c5b3074f972b8da450655897c3ae0b37 Mon Sep 17 00:00:00 2001 From: Ahmed Abdalla Date: Mon, 15 Jun 2020 19:00:33 +0200 Subject: [PATCH 10/10] Clean up conformance tests helper metadata --- test/conformance/helpers/metadata.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/conformance/helpers/metadata.go b/test/conformance/helpers/metadata.go index d56282c8b91..f1346f1e3ba 100644 --- a/test/conformance/helpers/metadata.go +++ b/test/conformance/helpers/metadata.go @@ -24,17 +24,13 @@ import ( func validateRequiredLabels(client *testlib.Client, object metav1.TypeMeta, labels map[string]string) { for k, v := range labels { - yes, err := objectHasRequiredLabel(client, object, k, v) - if err != nil { - client.T.Fatalf("error while checking labels for %q: %v", object, err) - } - if !yes { + if !objectHasRequiredLabel(client, object, k, v) { client.T.Fatalf("can't find label '%s=%s' in CRD %q", k, v, object) } } } -func objectHasRequiredLabel(client *testlib.Client, object metav1.TypeMeta, key string, value string) (bool, error) { +func objectHasRequiredLabel(client *testlib.Client, object metav1.TypeMeta, key string, value string) bool { gvr, _ := meta.UnsafeGuessKindToResource(object.GroupVersionKind()) crdName := gvr.Resource + "." + gvr.Group @@ -42,7 +38,7 @@ func objectHasRequiredLabel(client *testlib.Client, object metav1.TypeMeta, key TypeMeta: metav1.TypeMeta{}, }) if err != nil { - return false, err + client.T.Errorf("error while getting %q:%v", object, err) } - return crd.Labels[key] == value, nil + return crd.Labels[key] == value }