-
Notifications
You must be signed in to change notification settings - Fork 581
/
source_to_sink.go
68 lines (51 loc) · 2.18 KB
/
source_to_sink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
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 broker
import (
"context"
"testing"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/eventing/test/rekt/features"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/svc"
"knative.dev/eventing/test/rekt/resources/trigger"
. "github.com/cloudevents/sdk-go/v2/test"
. "knative.dev/reconciler-test/pkg/eventshub/assert"
)
// SourceToSink tests to see if a Ready Broker acts as middleware.
// LoadGenerator --> in [Broker] out --> Recorder
func SourceToSink(brokerName string) *feature.Feature {
source := feature.MakeRandomK8sName("source")
sink := feature.MakeRandomK8sName("sink")
via := feature.MakeRandomK8sName("via")
event := FullEvent()
f := new(feature.Feature)
f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
// Point the Trigger subscriber to the sink svc.
cfg := []trigger.CfgFn{trigger.WithSubscriber(svc.AsRef(sink), "")}
// Install the trigger
f.Setup("install trigger", trigger.Install(via, brokerName, cfg...))
f.Setup("trigger goes ready", trigger.IsReady(via, features.Interval, features.Timeout))
f.Setup("install source", func(ctx context.Context, t *testing.T) {
u, err := broker.Address(ctx, brokerName, features.Interval, features.Timeout)
if err != nil || u == nil {
t.Error("failed to get the address of the broker", brokerName, err)
}
eventshub.Install(source, eventshub.StartSenderURL(u.String()), eventshub.InputEvent(event))(ctx, t)
})
f.Stable("broker as middleware").
Must("deliver an event",
OnStore(sink).MatchEvent(HasId(event.ID())).Exact(1))
return f
}