Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sources metadata conformance test #3319

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
func BrokerV1Beta1ControlPlaneTestHelperWithChannelTestRunner(
t *testing.T,
brokerClass string,
channelTestRunner lib.ChannelTestRunner,
channelTestRunner lib.ComponentsTestRunner,
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, will do

setupClient ...lib.SetupClientOption,
) {
channelTestRunner.RunTests(t, lib.FeatureBasic, func(t *testing.T, channel metav1.TypeMeta) {
Expand Down
4 changes: 2 additions & 2 deletions test/conformance/helpers/broker_tracing_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestChannelAddressableResolverClusterRoleTestRunner(
t *testing.T,
channelTestRunner lib.ChannelTestRunner,
channelTestRunner lib.ComponentsTestRunner,
options ...lib.SetupClientOption,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestChannelChannelableManipulatorClusterRoleTestRunner(
t *testing.T,
channelTestRunner lib.ChannelTestRunner,
channelTestRunner lib.ComponentsTestRunner,
options ...lib.SetupClientOption,
) {

Expand Down
29 changes: 10 additions & 19 deletions test/conformance/helpers/channel_crd_metadata_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ import (
"knative.dev/eventing/test/lib"
)

var channelLabels = map[string]string{
Copy link
Member

Choose a reason for hiding this comment

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

👍

"messaging.knative.dev/subscribable": "true",
"duck.knative.dev/addressable": "true",
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have constants for those labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

none that I know of, lemme know if you know them

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

}

// 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,
) {

Expand All @@ -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)
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/conformance/helpers/channel_crd_name_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/helpers/channel_spec_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

func ChannelSpecTestHelperWithChannelTestRunner(
t *testing.T,
channelTestRunner lib.ChannelTestRunner,
channelTestRunner lib.ComponentsTestRunner,
options ...lib.SetupClientOption,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

Expand Down
4 changes: 2 additions & 2 deletions test/conformance/helpers/channel_status_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

Expand Down
4 changes: 2 additions & 2 deletions test/conformance/helpers/channel_tracing_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions test/conformance/helpers/metadata.go
Original file line number Diff line number Diff line change
@@ -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
}
48 changes: 48 additions & 0 deletions test/conformance/helpers/source_crd_metadata_test_helper.go
Original file line number Diff line number Diff line change
@@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as before, don't we have constants?

}

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

})
}
12 changes: 8 additions & 4 deletions test/conformance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ import (
"knative.dev/eventing/test/lib"
)

var channelTestRunner lib.ChannelTestRunner
var channelTestRunner lib.ComponentsTestRunner
var sourcesTestRunner lib.ComponentsTestRunner
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

Those 2 are somewhat related and deserve to be grouped, either as

var (
	channelTestRunner lib.ComponentsTestRunner
	sourcesTestRunner lib.ComponentsTestRunner
)

or

var channelTestRunner, 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

Expand Down
28 changes: 28 additions & 0 deletions test/conformance/source_crd_metadata_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion test/e2e/helpers/broker_channel_flow_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/channel_chain_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/helpers/channel_defaulter_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/channel_dls_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/channel_single_event_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers/parallel_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading