Skip to content

Commit

Permalink
Additional logging for sacura tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Nov 19, 2024
1 parent 036d8d8 commit 06e7405
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/e2e/sacura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package e2e

import (
"context"
"encoding/json"
"fmt"
"strings"
"testing"
Expand All @@ -31,16 +32,20 @@ import (
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/client-go/dynamic"
"k8s.io/utils/pointer"
sources "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
"knative.dev/eventing-kafka-broker/control-plane/pkg/kafka"
eventing "knative.dev/eventing/pkg/apis/eventing/v1"
messaging "knative.dev/eventing/pkg/apis/messaging/v1"
eventingclientset "knative.dev/eventing/pkg/client/clientset/versioned"
testlib "knative.dev/eventing/test/lib"
"knative.dev/pkg/ptr"

sources "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
"knative.dev/eventing-kafka-broker/control-plane/pkg/kafka"

pkgtest "knative.dev/eventing-kafka-broker/test/pkg"
kafkatest "knative.dev/eventing-kafka-broker/test/pkg/kafka"
Expand All @@ -64,6 +69,8 @@ type SacuraTestConfig struct {
// Namespace is the test namespace.
Namespace string

ConsumerResourceGVR schema.GroupVersionResource

// BrokerTopic is the expected Broker topic.
// It's used to verify the committed offset.
BrokerTopic *string
Expand All @@ -79,14 +86,16 @@ type SacuraTestConfig struct {

func TestSacuraSinkSourceJob(t *testing.T) {
runSacuraTest(t, SacuraTestConfig{
Namespace: "sacura-sink-source",
SourceTopic: pointer.String("sacura-sink-source-topic"),
Namespace: "sacura-sink-source",
ConsumerResourceGVR: sources.SchemeGroupVersion.WithResource("kafkasources"),
SourceTopic: pointer.String("sacura-sink-source-topic"),
})
}

func TestSacuraBrokerJob(t *testing.T) {
runSacuraTest(t, SacuraTestConfig{
Namespace: "sacura",
ConsumerResourceGVR: eventing.SchemeGroupVersion.WithResource("triggers"),
BrokerTopic: pointer.String("knative-broker-sacura-sink-source-broker"),
})
}
Expand All @@ -98,6 +107,21 @@ func runSacuraTest(t *testing.T, config SacuraTestConfig) {

ctx := context.Background()

w, err := c.Dynamic.Resource(config.ConsumerResourceGVR).
Namespace(config.Namespace).
Watch(ctx, metav1.ListOptions{Watch: true, SendInitialEvents: ptr.Bool(true)})
if err != nil {
t.Fatal(err)
}
defer w.Stop()

go func() {
for e := range w.ResultChan() {
bytes, _ := json.MarshalIndent(e, "", " ")
t.Logf("Consumer resource %q changed:\n%s\n\n", config.ConsumerResourceGVR.String(), string(bytes))
}
}()

jobPollError := wait.Poll(pollInterval, pollTimeout, func() (done bool, err error) {
job, err := c.Kube.BatchV1().Jobs(config.Namespace).Get(ctx, app, metav1.GetOptions{})
assert.Nil(t, err)
Expand Down

0 comments on commit 06e7405

Please sign in to comment.