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

test SinkBinding with eventshub TLS receiver as sink #6961

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/rekt/features/sinkbinding/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ func SinkBindingV1Job(ctx context.Context) *feature.Feature {
return f
}

func SinkBindingV1DeploymentTLS(ctx context.Context) *feature.Feature {
sbinding := feature.MakeRandomK8sName("sinkbinding")
sink := feature.MakeRandomK8sName("sink")

f := feature.NewFeatureNamed("SinkBinding V1 Deployment test with TLS")

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

f.Requirement("install SinkBinding", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(sink)
d.CACerts = eventshub.GetCaCerts(ctx)

cfg = append(cfg, sinkbinding.WithSink(d))
sinkbinding.Install(sbinding, cfg...)(ctx, t)
})
f.Requirement("SinkBinding goes ready", sinkbinding.IsReady(sbinding))
f.Stable("SinkBinding as event source").
Must("delivers events on sink with ref",
eventasssert.OnStore(sink).
Match(eventasssert.MatchKind(eventshub.EventReceived)).
AtLeast(1),
)
return f
}
taniaduggal marked this conversation as resolved.
Show resolved Hide resolved

// AsTrackerReference returns a tracker.Reference for a Job without namespace.
func AsTrackerReference(name string) *tracker.Reference {
return &tracker.Reference{
Expand Down
33 changes: 33 additions & 0 deletions test/rekt/resources/sinkbinding/sinkbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package sinkbinding
import (
"context"
"embed"
"strings"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -106,6 +107,38 @@ func WithExtensions(extensions map[string]string) manifest.CfgFn {
}
}

func WithSink(d *duckv1.Destination) manifest.CfgFn {
return func(cfg map[string]interface{}) {
if _, set := cfg["sink"]; !set {
cfg["sink"] = map[string]interface{}{}
}
sink := cfg["sink"].(map[string]interface{})

ref := d.Ref
uri := d.URI

if d.CACerts != nil {
// This is a multi-line string and should be indented accordingly.
// Replace "new line" with "new line + spaces".
sink["CACerts"] = strings.ReplaceAll(*d.CACerts, "\n", "\n ")
}

if uri != nil {
sink["uri"] = uri.String()
}
if ref != nil {
if _, set := sink["ref"]; !set {
sink["ref"] = map[string]interface{}{}
}
sref := sink["ref"] = map[string]interface{}{}
sref["apiVersion"] = ref.APIVersion
sref["kind"] = ref.Kind
// skip namespace
sref["name"] = ref.Name
}
}
}

// IsReady tests to see if a PingSource becomes ready within the time given.
func IsReady(name string, timing ...time.Duration) feature.StepFn {
return k8s.IsReady(Gvr(), name, timing...)
Expand Down
4 changes: 4 additions & 0 deletions test/rekt/resources/sinkbinding/sinkbinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ spec:
namespace: {{ .namespace }}
name: {{ .sink.ref.name }}
{{ end }}
{{ if .sink.CACerts }}
CACerts: |-
{{ .sink.CACerts }}
{{ end }}
{{ if .sink.uri }}
uri: {{ .sink.uri }}
{{ end }}
Expand Down
39 changes: 39 additions & 0 deletions test/rekt/resources/sinkbinding/sinkbinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,42 @@ func Example_full() {
// match1: this
// match2: that
}

func Example_withSink() {
ctx := testlog.NewContext()
images := map[string]string{}
cfg := map[string]interface{}{
"name": "foo",
"namespace": "bar",
}

sinkRef := &duckv1.Destination{
Ref: &duckv1.KReference{
Kind: "sinkkind",
Namespace: "sinknamespace",
Name: "sinkname",
APIVersion: "sinkversion",
},
URI: &apis.URL{Path: "uri/parts"},
}
sinkbinding.WithSink(sinkRef)(cfg)
files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
if err != nil {
panic(err)
}

manifest.OutputYAML(os.Stdout, files)
// Output:
// apiVersion: sources.knative.dev/v1
// kind: SinkBinding
// metadata:
// name: foo
// namespace: bar
// spec:
// sink:
// ref:
// kind: sinkkind
// namespace: bar
// name: sinkname
// apiVersion: sinkversion
// uri: uri/parts
17 changes: 17 additions & 0 deletions test/rekt/sink_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/knative"

Expand All @@ -45,6 +46,22 @@ func TestSinkBindingV1Deployment(t *testing.T) {
env.Test(ctx, t, sinkbinding.SinkBindingV1Deployment(ctx))
}

func TestSinkBindingV1DeploymentTLS(t *testing.T) {
t.Parallel()

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

env.Test(ctx, t, sinkbinding.SinkBindingV1DeploymentTLS(ctx))
}

func TestSinkBindingV1Job(t *testing.T) {
t.Parallel()

Expand Down