Skip to content

Commit fce0712

Browse files
nachocanoknative-prow-robot
authored andcommitted
Backport fix to e2e tests infra - Cherry-pick #2176 (#2181)
* fix a nit variable naming (#2166) (#2173) * Channel tests key off of a full TypeMeta (#2176) * Channel tests key off of a full TypeMeta, not just a Kind that assumes messaging.knative.dev/v1alpha1. * Update the parallel and sequence tests. * Flag specified channels assume all features. # Conflicts: # test/e2e/flows_parallel_test.go # test/e2e/flows_sequence_test.go
1 parent 6864f74 commit fce0712

17 files changed

+85
-81
lines changed

test/common/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ limitations under the License.
1717
package common
1818

1919
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021
"knative.dev/eventing/test/base/resources"
2122
)
2223

2324
// DefaultChannel is the default channel we will run tests against.
24-
const DefaultChannel = resources.InMemoryChannelKind
25+
var DefaultChannel = InMemoryChannelTypeMeta
26+
27+
// InMemoryChannelTypeMeta is the metav1.TypeMeta for InMemoryChannel.
28+
var InMemoryChannelTypeMeta = metav1.TypeMeta{
29+
APIVersion: resources.MessagingAPIVersion,
30+
Kind: resources.InMemoryChannelKind,
31+
}
2532

2633
// ChannelFeatureMap saves the channel-features mapping.
2734
// Each pair means the channel support the list of features.
28-
var ChannelFeatureMap = map[string][]Feature{
29-
resources.InMemoryChannelKind: {FeatureBasic},
35+
var ChannelFeatureMap = map[metav1.TypeMeta][]Feature{
36+
InMemoryChannelTypeMeta: {FeatureBasic},
3037
}
3138

3239
// Feature is the feature supported by the channel.

test/common/test_runner.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,25 @@ const TestPullSecretName = "kn-eventing-test-pull-secret"
4545

4646
// ChannelTestRunner is used to run tests against channels.
4747
type ChannelTestRunner struct {
48-
ChannelFeatureMap map[string][]Feature
49-
ChannelsToTest []string
48+
ChannelFeatureMap map[metav1.TypeMeta][]Feature
49+
ChannelsToTest []metav1.TypeMeta
5050
}
5151

5252
// RunTests will use all channels that support the given feature, to run
5353
// a test for the testFunc.
5454
func (tr *ChannelTestRunner) RunTests(
5555
t *testing.T,
5656
feature Feature,
57-
testFunc func(st *testing.T, channel string),
57+
testFunc func(st *testing.T, channel metav1.TypeMeta),
5858
) {
5959
t.Parallel()
6060
for _, channel := range tr.ChannelsToTest {
61-
features := tr.ChannelFeatureMap[channel]
62-
if contains(features, feature) {
61+
// If a Channel is not present in the map, then assume it has all properties. This is so an
62+
// unknown Channel can be specified via the --channel flag and have tests run.
63+
// TODO Use a flag to specify the features of the flag based Channel, rather than assuming
64+
// it supports all features.
65+
features, present := tr.ChannelFeatureMap[channel]
66+
if !present || contains(features, feature) {
6367
t.Run(fmt.Sprintf("%s-%s", t.Name(), channel), func(st *testing.T) {
6468
testFunc(st, channel)
6569
})

test/common/typemeta.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ func SourcesTypeMeta(kind string) *metav1.TypeMeta {
5555
}
5656
}
5757

58-
// GetChannelTypeMeta gets the actual typemeta of the typed channel.
59-
func GetChannelTypeMeta(channelKind string) *metav1.TypeMeta {
60-
return MessagingTypeMeta(channelKind)
61-
}
62-
6358
// ChannelTypeMeta is the TypeMeta ref for Channel.
6459
var ChannelTypeMeta = MessagingTypeMeta(resources.ChannelKind)
6560

test/conformance/helpers/broker_tracing_test_helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ func BrokerTracingTestHelperWithChannelTestRunner(
3737
channelTestRunner common.ChannelTestRunner,
3838
setupClient SetupClientFunc,
3939
) {
40-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
40+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
4141
// Don't accidentally use t, use st instead. To ensure this, shadow 't' to a useless type.
4242
t := struct{}{}
4343
_ = fmt.Sprintf("%s", t)
4444

45-
channelTypeMeta := common.GetChannelTypeMeta(channel)
46-
BrokerTracingTestHelper(st, *channelTypeMeta, setupClient)
45+
BrokerTracingTestHelper(st, channel, setupClient)
4746
})
4847
}
4948

test/conformance/helpers/channel_header_single_event_helper.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"testing"
2222

23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/util/uuid"
2425
"knative.dev/eventing/test/base/resources"
2526
"knative.dev/eventing/test/common"
@@ -39,15 +40,14 @@ func SingleEventHelperForChannelTestHelper(t *testing.T, encoding string, channe
3940
subscriptionName := "conformance-headers-subscription-" + encoding
4041
loggerPodName := "conformance-headers-logger-pod-" + encoding
4142

42-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
43+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
4344
st.Logf("Running header conformance test with channel %q", channel)
4445
client := common.Setup(st, true)
4546
defer common.TearDown(client)
4647

4748
// create channel
4849
st.Logf("Creating channel")
49-
channelTypeMeta := common.GetChannelTypeMeta(channel)
50-
client.CreateChannelOrFail(channelName, channelTypeMeta)
50+
client.CreateChannelOrFail(channelName, &channel)
5151

5252
// create logger service as the subscriber
5353
pod := resources.EventDetailsPod(loggerPodName)
@@ -57,7 +57,7 @@ func SingleEventHelperForChannelTestHelper(t *testing.T, encoding string, channe
5757
client.CreateSubscriptionOrFail(
5858
subscriptionName,
5959
channelName,
60-
channelTypeMeta,
60+
&channel,
6161
resources.WithSubscriberForSubscription(loggerPodName),
6262
)
6363

@@ -78,7 +78,7 @@ func SingleEventHelperForChannelTestHelper(t *testing.T, encoding string, channe
7878
}
7979

8080
st.Logf("Sending event with tracing headers to %s", senderName)
81-
if err := client.SendFakeEventWithTracingToAddressable(senderName, channelName, channelTypeMeta, event); err != nil {
81+
if err := client.SendFakeEventWithTracingToAddressable(senderName, channelName, &channel, event); err != nil {
8282
st.Fatalf("Failed to send fake CloudEvent to the channel %q", channelName)
8383
}
8484

test/conformance/helpers/channel_tracing_test_helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ func ChannelTracingTestHelperWithChannelTestRunner(
6767
channelTestRunner common.ChannelTestRunner,
6868
setupClient SetupClientFunc,
6969
) {
70-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
70+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
7171
// Don't accidentally use t, use st instead. To ensure this, shadow 't' to a useless type.
7272
t := struct{}{}
7373
_ = fmt.Sprintf("%s", t)
7474

75-
channelTypeMeta := common.GetChannelTypeMeta(channel)
76-
ChannelTracingTestHelper(st, *channelTypeMeta, setupClient)
75+
ChannelTracingTestHelper(st, channel, setupClient)
7776
})
7877
}
7978

test/conformance/main_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ import (
2525
"knative.dev/pkg/test/zipkin"
2626
)
2727

28-
var setup = common.Setup
29-
var tearDown = common.TearDown
30-
var getChannelTypeMeta = common.GetChannelTypeMeta
31-
var channels test.Channels
3228
var channelTestRunner common.ChannelTestRunner
3329

3430
func TestMain(m *testing.M) {
3531
os.Exit(func() int {
3632
test.InitializeEventingFlags()
37-
channels = test.EventingFlags.Channels
3833
channelTestRunner = common.ChannelTestRunner{
3934
ChannelFeatureMap: common.ChannelFeatureMap,
4035
ChannelsToTest: test.EventingFlags.Channels,

test/e2e/helpers/broker_channel_flow_test_helper.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"testing"
2121

22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
"k8s.io/apimachinery/pkg/util/uuid"
2324
"knative.dev/eventing/pkg/apis/eventing/v1alpha1"
2425
"knative.dev/eventing/test/base/resources"
@@ -50,16 +51,15 @@ func BrokerChannelFlowTestHelper(t *testing.T, channelTestRunner common.ChannelT
5051
subscriptionName = "e2e-brokerchannel-subscription"
5152
)
5253

53-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
54+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
5455
client := common.Setup(st, true)
5556
defer common.TearDown(client)
56-
channelTypeMeta := common.GetChannelTypeMeta(channel)
5757

5858
// create required RBAC resources including ServiceAccounts and ClusterRoleBindings for Brokers
5959
client.CreateRBACResourcesForBrokers()
6060

6161
// create a new broker
62-
client.CreateBrokerOrFail(brokerName, channelTypeMeta)
62+
client.CreateBrokerOrFail(brokerName, &channel)
6363
client.WaitForResourceReady(brokerName, common.BrokerTypeMeta)
6464

6565
// create the event we want to transform to
@@ -96,11 +96,11 @@ func BrokerChannelFlowTestHelper(t *testing.T, channelTestRunner common.ChannelT
9696
)
9797

9898
// create channel for trigger3
99-
client.CreateChannelOrFail(channelName, channelTypeMeta)
100-
client.WaitForResourceReady(channelName, channelTypeMeta)
99+
client.CreateChannelOrFail(channelName, &channel)
100+
client.WaitForResourceReady(channelName, &channel)
101101

102102
// create trigger3 to receive the transformed event, and send it to the channel
103-
channelURL, err := client.GetAddressableURI(channelName, channelTypeMeta)
103+
channelURL, err := client.GetAddressableURI(channelName, &channel)
104104
if err != nil {
105105
st.Fatalf("Failed to get the url for the channel %q: %v", channelName, err)
106106
}
@@ -119,7 +119,7 @@ func BrokerChannelFlowTestHelper(t *testing.T, channelTestRunner common.ChannelT
119119
client.CreateSubscriptionOrFail(
120120
subscriptionName,
121121
channelName,
122-
channelTypeMeta,
122+
&channel,
123123
resources.WithSubscriberForSubscription(loggerPodName2),
124124
)
125125

test/e2e/helpers/broker_event_transformation_test_helper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"testing"
2121

22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
"k8s.io/apimachinery/pkg/util/uuid"
2324
"knative.dev/eventing/pkg/apis/eventing/v1alpha1"
2425
"knative.dev/eventing/test/base/resources"
@@ -45,16 +46,15 @@ func EventTransformationForTriggerTestHelper(t *testing.T, channelTestRunner com
4546
loggerPodName = "logger-pod"
4647
)
4748

48-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
49+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
4950
client := common.Setup(st, true)
5051
defer common.TearDown(client)
51-
channelTypeMeta := common.GetChannelTypeMeta(channel)
5252

5353
// create required RBAC resources including ServiceAccounts and ClusterRoleBindings for Brokers
5454
client.CreateRBACResourcesForBrokers()
5555

5656
// create a new broker
57-
client.CreateBrokerOrFail(brokerName, channelTypeMeta)
57+
client.CreateBrokerOrFail(brokerName, &channel)
5858
client.WaitForResourceReady(brokerName, common.BrokerTypeMeta)
5959

6060
// create the event we want to transform to

test/e2e/helpers/channel_chain_test_helper.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"testing"
2222

23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/util/uuid"
2425
"knative.dev/eventing/test/base/resources"
2526
"knative.dev/eventing/test/common"
@@ -37,14 +38,13 @@ func ChannelChainTestHelper(t *testing.T, channelTestRunner common.ChannelTestRu
3738
// subscriptionNames2 corresponds to Subscriptions on channelNames[1]
3839
subscriptionNames2 := []string{"e2e-channelchain-subs21"}
3940

40-
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel string) {
41+
channelTestRunner.RunTests(t, common.FeatureBasic, func(st *testing.T, channel metav1.TypeMeta) {
4142
client := common.Setup(st, true)
4243
defer common.TearDown(client)
4344

4445
// create channels
45-
channelTypeMeta := common.GetChannelTypeMeta(channel)
46-
client.CreateChannelsOrFail(channelNames, channelTypeMeta)
47-
client.WaitForResourcesReady(channelTypeMeta)
46+
client.CreateChannelsOrFail(channelNames, &channel)
47+
client.WaitForResourcesReady(&channel)
4848

4949
// create loggerPod and expose it as a service
5050
pod := resources.EventLoggerPod(loggerPodName)
@@ -54,14 +54,14 @@ func ChannelChainTestHelper(t *testing.T, channelTestRunner common.ChannelTestRu
5454
client.CreateSubscriptionsOrFail(
5555
subscriptionNames1,
5656
channelNames[0],
57-
channelTypeMeta,
58-
resources.WithReplyForSubscription(channelNames[1], channelTypeMeta),
57+
&channel,
58+
resources.WithReplyForSubscription(channelNames[1], &channel),
5959
)
6060
// create subscriptions that subscribe the second channel, and call the logging service
6161
client.CreateSubscriptionsOrFail(
6262
subscriptionNames2,
6363
channelNames[1],
64-
channelTypeMeta,
64+
&channel,
6565
resources.WithSubscriberForSubscription(loggerPodName),
6666
)
6767

@@ -78,7 +78,7 @@ func ChannelChainTestHelper(t *testing.T, channelTestRunner common.ChannelTestRu
7878
Data: fmt.Sprintf(`{"msg":%q}`, body),
7979
Encoding: resources.CloudEventDefaultEncoding,
8080
}
81-
if err := client.SendFakeEventToAddressable(senderName, channelNames[0], channelTypeMeta, event); err != nil {
81+
if err := client.SendFakeEventToAddressable(senderName, channelNames[0], &channel, event); err != nil {
8282
st.Fatalf("Failed to send fake CloudEvent to the channel %q", channelNames[0])
8383
}
8484

0 commit comments

Comments
 (0)