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..c4f6b92ea14 100644 --- a/test/conformance/helpers/channel_crd_metadata_test_helper.go +++ b/test/conformance/helpers/channel_crd_metadata_test_helper.go @@ -25,11 +25,16 @@ 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 ChannelTestRunner. +// Channel resources in the ComponentsTestRunner. func ChannelCRDMetadataTestHelperWithChannelTestRunner( t *testing.T, - channelTestRunner lib.ChannelTestRunner, + channelTestRunner lib.ComponentsTestRunner, options ...lib.SetupClientOption, ) { @@ -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,27 +66,13 @@ 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) - } + validateRequiredLabels(client, channel, channelLabels) } func channelCRDHasProperCategory(st *testing.T, client *lib.Client, channel metav1.TypeMeta) { 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/helpers/metadata.go b/test/conformance/helpers/metadata.go new file mode 100644 index 00000000000..f1346f1e3ba --- /dev/null +++ b/test/conformance/helpers/metadata.go @@ -0,0 +1,44 @@ +/* +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" + testlib "knative.dev/eventing/test/lib" +) + +func validateRequiredLabels(client *testlib.Client, object metav1.TypeMeta, labels map[string]string) { + for k, v := range labels { + 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 { + 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 { + client.T.Errorf("error while getting %q:%v", object, err) + } + return crd.Labels[key] == value +} 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..75630099d7f --- /dev/null +++ b/test/conformance/helpers/source_crd_metadata_test_helper.go @@ -0,0 +1,48 @@ +/* +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 ( + "testing" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/eventing/test/lib" +) + +var sourceLabels = map[string]string{ + "duck.knative.dev/source": "true", +} + +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) + + // 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) { + validateRequiredLabels(client, source, sourceLabels) + }) + + }) +} 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/conformance/source_crd_metadata_test.go b/test/conformance/source_crd_metadata_test.go new file mode 100644 index 00000000000..e388911bd03 --- /dev/null +++ b/test/conformance/source_crd_metadata_test.go @@ -0,0 +1,28 @@ +/* +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 ( + "testing" + + "knative.dev/eventing/test/conformance/helpers" + "knative.dev/eventing/test/lib" +) + +func TestSourceCRDMetadata(t *testing.T) { + helpers.SourceCRDMetadataTestHelperWithChannelTestRunner(t, sourcesTestRunner, lib.SetupClientOptionNoop) +} 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/e2e_flags.go b/test/e2e_flags.go index 9397a67d5b2..74228eb6a33 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -21,63 +21,35 @@ 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" ) -// 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") -} +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\"." +) -// EventingEnvironmentFlags holds the e2e flags needed only by the eventing repo. -type EventingEnvironmentFlags struct { - BrokerClass string - Channels -} +// EventingFlags holds the command line flags specific to knative/eventing. +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..d4ff2cc22b5 --- /dev/null +++ b/test/flags/channels.go @@ -0,0 +1,58 @@ +/* +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 ( + "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 appends 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..65a05dd7ac4 --- /dev/null +++ b/test/flags/eventing_environment.go @@ -0,0 +1,24 @@ +/* +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 { + BrokerClass string + Channels + Sources +} diff --git a/test/flags/sources.go b/test/flags/sources.go new file mode 100644 index 00000000000..cc3e016b4db --- /dev/null +++ b/test/flags/sources.go @@ -0,0 +1,58 @@ +/* +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 ( + "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 appends 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") +} 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()) }