Skip to content

Commit

Permalink
Knative port prefer header check test to rekt (#6499)
Browse files Browse the repository at this point in the history
* port PreferHeaderCheck test of broker and channel to rekt

* remove old e2e test

* code cleanup
  • Loading branch information
liuchangyan authored Sep 6, 2022
1 parent f63a073 commit 7f1f49f
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 267 deletions.
36 changes: 0 additions & 36 deletions test/e2e/broker_prefer_reply_header_test.go

This file was deleted.

35 changes: 0 additions & 35 deletions test/e2e/channel_prefer_reply_header_test.go

This file was deleted.

97 changes: 0 additions & 97 deletions test/e2e/helpers/broker_prefer_reply_header_helper.go

This file was deleted.

99 changes: 0 additions & 99 deletions test/e2e/helpers/channel_prefer_reply_header_helper.go

This file was deleted.

15 changes: 15 additions & 0 deletions test/rekt/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,18 @@ func TestBrokerDefaultDelivery(t *testing.T) {

env.Test(ctx, t, broker.DefaultDeliverySpec())
}

//TestBrokerPreferHeaderCheck test if the test message without explicit prefer header
//should have it after fanout.
func TestBrokerPreferHeaderCheck(t *testing.T) {
ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
environment.WithPollTimings(5*time.Second, 4*time.Minute),
)

env.Test(ctx, t, broker.BrokerPreferHeaderCheck())
}
20 changes: 20 additions & 0 deletions test/rekt/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,23 @@ func TestStructuredEventForChannel(t *testing.T) {

env.Test(ctx, t, channel.SingleEventWithEncoding(binding.EncodingStructured))
}

//TestChannelPreferHeaderCheck test if the test message without explicit prefer header
//should have it after fanout.
func TestChannelPreferHeaderCheck(t *testing.T) {
t.Parallel()

ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)

createSubscriberFn := func(ref *duckv1.KReference, uri string) manifest.CfgFn {
return subscription.WithSubscriber(ref, uri)
}

env.Test(ctx, t, channel.ChannelPreferHeaderCheck(createSubscriberFn))
}
76 changes: 76 additions & 0 deletions test/rekt/features/broker/feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2022 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 broker

import (
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/google/uuid"
"knative.dev/reconciler-test/pkg/eventshub"
eventasssert "knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/resources/svc"

"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/trigger"
"knative.dev/reconciler-test/pkg/manifest"
)

func BrokerPreferHeaderCheck() *feature.Feature {
f := feature.NewFeatureNamed("Channel PreferHeader Check")

source := feature.MakeRandomK8sName("source")
sink := feature.MakeRandomK8sName("sink")
via := feature.MakeRandomK8sName("via")

eventSource := "source1"
eventType := "type1"
eventBody := `{"msg":"test msg"}`
event := cloudevents.NewEvent()
event.SetID(uuid.New().String())
event.SetType(eventType)
event.SetSource(eventSource)
event.SetData(cloudevents.ApplicationJSON, []byte(eventBody))

//Install the broker
brokerName := feature.MakeRandomK8sName("broker")
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Requirement("broker is ready", broker.IsReady(brokerName))
f.Requirement("broker is addressable", broker.IsAddressable(brokerName))

f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))

// Point the Trigger subscriber to the sink svc.
cfg := []manifest.CfgFn{trigger.WithSubscriber(svc.AsKReference(sink), "")}

// Install the trigger
f.Setup("install trigger", trigger.Install(via, brokerName, cfg...))
f.Setup("trigger goes ready", trigger.IsReady(via))

f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(event),
))

f.Stable("test message without explicit prefer header should have the header").
Must("delivers events",
eventasssert.OnStore(sink).Match(
eventasssert.HasAdditionalHeader("Prefer", "reply"),
).AtLeast(1))

return f
}
Loading

0 comments on commit 7f1f49f

Please sign in to comment.