Skip to content

Commit

Permalink
Move eventtype rekttest pingsource to experiment (knative#7180)
Browse files Browse the repository at this point in the history
* Fix the merge conflict and fix the logical error in the test

Signed-off-by: Leo Li <[email protected]>

* Add the auto eventType creation support

Signed-off-by: Leo Li <[email protected]>

* reformat and remove the comments

Signed-off-by: Leo Li <[email protected]>

* Remove the assertReference function

Signed-off-by: Leo Li <[email protected]>

* fix reviewDog issue

Signed-off-by: Leo Li <[email protected]>

* Update test/rekt/resources/eventtype/eventtype.go

Co-authored-by: Calum Murray <[email protected]>

* fix reviewDog issue

Signed-off-by: Leo Li <[email protected]>

* Move the test to experimental rekt

Signed-off-by: Leo Li <[email protected]>

* Remove the eventtype test from the pingsource rekt test

Signed-off-by: Leo Li <[email protected]>

* Rename the test name to make it more intuitive

Signed-off-by: Leo Li <[email protected]>

* Revert the unit test change

Signed-off-by: Leo Li <[email protected]>

* Format fix

Signed-off-by: Leo Li <[email protected]>

* format fix

Signed-off-by: Leo Li <[email protected]>

* Fix Christoph's comment

Signed-off-by: Leo Li <[email protected]>

* go imports

Signed-off-by: Leo Li <[email protected]>

* Update test/experimental/features/eventtype_autocreation/eventtype.go

Co-authored-by: Christoph Stäbler <[email protected]>

* Update test/experimental/eventtype_autocreation_test.go

Co-authored-by: Christoph Stäbler <[email protected]>

* Apply suggestions from code review

Co-authored-by: Christoph Stäbler <[email protected]>

* Change the name of the file

Signed-off-by: Leo Li <[email protected]>

* Update the deprecated string

Signed-off-by: Leo Li <[email protected]>

* Update test/rekt/features/pingsource/features.go

Co-authored-by: Calum Murray <[email protected]>

* Manually merge the chanhges from Calum's ticket

Signed-off-by: Leo Li <[email protected]>

* Manually merge the chanhges from Calum's ticket

Signed-off-by: Leo Li <[email protected]>

---------

Signed-off-by: Leo Li <[email protected]>
Co-authored-by: Calum Murray <[email protected]>
Co-authored-by: Christoph Stäbler <[email protected]>
Co-authored-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
4 people authored and mgencur committed Jan 24, 2024
1 parent 76cdd55 commit c8d12c3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
14 changes: 14 additions & 0 deletions test/experimental/eventtype_autocreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ func TestIMCEventTypeAutoCreate(t *testing.T) {

env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypesOnIMC())
}

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

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

env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypeEventsFromPingSource())
}
49 changes: 49 additions & 0 deletions test/experimental/features/eventtype_autocreate/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ limitations under the License.
package eventtype_autocreate

import (
"context"

"github.com/cloudevents/sdk-go/v2/test"
cetest "github.com/cloudevents/sdk-go/v2/test"
"k8s.io/apimachinery/pkg/util/sets"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/channel_impl"
"knative.dev/eventing/test/rekt/resources/eventtype"
"knative.dev/eventing/test/rekt/resources/pingsource"
"knative.dev/eventing/test/rekt/resources/subscription"
"knative.dev/eventing/test/rekt/resources/trigger"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/pkg/resources/service"
)

Expand Down Expand Up @@ -59,3 +68,43 @@ func AutoCreateEventTypesOnIMC() *feature.Feature {

return f
}

func AutoCreateEventTypeEventsFromPingSource() *feature.Feature {
source := feature.MakeRandomK8sName("source")
sink := feature.MakeRandomK8sName("sink")
via := feature.MakeRandomK8sName("via")

f := new(feature.Feature)

//Install the broker
brokerName := feature.MakeRandomK8sName("broker")
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Setup("broker is ready", broker.IsReady(brokerName))
f.Setup("broker is addressable", broker.IsAddressable(brokerName))
f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
f.Setup("install trigger", trigger.Install(via, brokerName, trigger.WithSubscriber(service.AsKReference(sink), "")))
f.Setup("trigger goes ready", trigger.IsReady(via))

f.Requirement("install pingsource", func(ctx context.Context, t feature.T) {
brokeruri, err := broker.Address(ctx, brokerName)
if err != nil {
t.Error("failed to get address of broker", err)
}
cfg := []manifest.CfgFn{
pingsource.WithSink(&duckv1.Destination{URI: brokeruri.URL, CACerts: brokeruri.CACerts}),
pingsource.WithData("text/plain", "hello, world!"),
}
pingsource.Install(source, cfg...)(ctx, t)
})
f.Requirement("PingSource goes ready", pingsource.IsReady(source))

expectedCeTypes := sets.New(sourcesv1.PingSourceEventType)

f.Stable("pingsource as event source").
Must("delivers events on broker with URI", assert.OnStore(sink).MatchEvent(
test.HasType(sourcesv1.PingSourceEventType)).AtLeast(1)).
Must("PingSource test eventtypes match", eventtype.WaitForEventType(
eventtype.AssertPresent(expectedCeTypes)))

return f
}
15 changes: 8 additions & 7 deletions test/rekt/features/pingsource/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,28 @@ package pingsource

import (
"context"

"github.com/cloudevents/sdk-go/v2/test"

"k8s.io/apimachinery/pkg/util/sets"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/eventtype"
"knative.dev/eventing/test/rekt/resources/trigger"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/reconciler-test/pkg/manifest"

"github.com/cloudevents/sdk-go/v2/test"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/pkg/resources/service"

"knative.dev/reconciler-test/pkg/eventshub/assert"
eventassert "knative.dev/reconciler-test/pkg/eventshub/assert"

sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/test/rekt/features"
"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/features/source"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/eventtype"
"knative.dev/eventing/test/rekt/resources/pingsource"
"knative.dev/eventing/test/rekt/resources/trigger"
)

func SendsEventsWithSinkRef() *feature.Feature {
Expand Down
16 changes: 0 additions & 16 deletions test/rekt/pingsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package rekt

import (
"testing"
"time"

"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/environment"
Expand Down Expand Up @@ -90,18 +89,3 @@ func TestPingSourceWithCloudEventData(t *testing.T) {

env.Test(ctx, t, pingsource.SendsEventsWithCloudEventData())
}

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

ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
environment.WithPollTimings(5*time.Second, 2*time.Minute),
)

env.Test(ctx, t, pingsource.SendsEventsWithEventTypes())
}

0 comments on commit c8d12c3

Please sign in to comment.