-
Notifications
You must be signed in to change notification settings - Fork 600
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
[WIP] Add reconciler test for EventType references #7114
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f62f452
Add some initial attempt code
Leo6Leo 16a3d37
Add some comments, waiting for the reply from the upstream to the que…
Leo6Leo 66e74e3
Add the AssertReferenceKind function
Leo6Leo 560a7f2
Merge branch 'main' into rekt-test-for-eventType
Leo6Leo 03dcddd
fix the public function issue
Leo6Leo 1853421
Add some loggers for debugging purposes
Leo6Leo 86e9804
Merge branch 'main' into rekt-test-for-eventType
Leo6Leo b68a358
Merge branch 'main' into rekt-test-for-eventType
Leo6Leo 9a81be4
Merge branch 'main' into rekt-test-for-eventType
Leo6Leo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
/* | ||
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 rekt | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"eventing/test/rekt/features/eventtype" | ||
"knative.dev/pkg/system" | ||
_ "knative.dev/pkg/system/testing" | ||
"knative.dev/reconciler-test/pkg/environment" | ||
"knative.dev/reconciler-test/pkg/k8s" | ||
"knative.dev/reconciler-test/pkg/knative" | ||
"knative.dev/reconciler-test/pkg/tracing" | ||
) | ||
|
||
func TestEventTypeWithBrokerAsReference(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, env := global.Environment( | ||
knative.WithKnativeNamespace(system.Namespace()), | ||
knative.WithLoggingConfig, | ||
knative.WithTracingConfig, | ||
k8s.WithEventListener, | ||
environment.Managed(t), | ||
tracing.WithGatherer(t), | ||
environment.WithPollTimings(5*time.Second, 4*time.Minute), | ||
) | ||
|
||
env.TestSet(ctx, t, eventtype.eventTypeWithBrokerAsReference()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
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 eventtype | ||
|
||
import ( | ||
cloudevents "github.com/cloudevents/sdk-go/v2" | ||
"github.com/google/uuid" | ||
duckv1 "knative.dev/eventing/pkg/apis/duck/v1" | ||
"knative.dev/eventing/test/rekt/resources/broker" | ||
"knative.dev/eventing/test/rekt/resources/eventtype" | ||
"knative.dev/eventing/test/rekt/resources/trigger" | ||
"knative.dev/pkg/ptr" | ||
"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" | ||
) | ||
|
||
func eventTypeWithBrokerAsReference(retryNum int32, dropNum uint) *feature.Feature { | ||
f := feature.NewFeatureNamed("Broker reply with a bad status code to the first n events") | ||
|
||
source := feature.MakeRandomK8sName("source") | ||
sink := feature.MakeRandomK8sName("sink") | ||
via := feature.MakeRandomK8sName("via") | ||
|
||
eventSource := "source2" | ||
eventType := "type2" | ||
eventBody := `{"msg":"DropN"}` | ||
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") | ||
exp := duckv1.BackoffPolicyLinear | ||
brokerConfig := append(broker.WithEnvConfig(), broker.WithRetry(retryNum, &exp, ptr.String("PT1S"))) | ||
|
||
f.Setup("install broker", broker.Install(brokerName, brokerConfig...)) | ||
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(service.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), | ||
)) | ||
|
||
// The eventType should be already auto-created. We then need to pop up the eventType in the event registry. | ||
// We need to validate the reference of the eventType is pointing to the broker. | ||
f.Stable("ApiServerSource as event source"). | ||
Must("ApiServerSource test eventtypes match", | ||
eventtype.WaitForEventType(eventtype.AssertReferenceMatch("InMemoryChannel"))) | ||
|
||
return f | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: I added the new module
eventtype
in rekt. How should I import the module here?Please lmk if this is not the right way to approach this ticket.
/cc @matzew @pierDipi @creydr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you're using an incorrect import path. The knative modules are all under
knative.dev/<repo>/...
(no matter if it is a knative-sandbox project or not). So in this case it would be"knative.dev/eventing/test/rekt/features/eventtype"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the approach: In the test files (under test/rekt//_test.go), we usually setup only the environment and call the feature test (as you have done). In the feature test (
test/rekt/features/
) we have the according test implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that before. If I use
knative.dev/eventing/test/rekt/features/eventtype
, it will throw this errortest/rekt/eventtype_test.go:47:32: undefined: eventtype.eventTypeWithBrokerAsReference
Does importing the packages that starting with
knative.dev/***
will actually download the latest knative package from the source? Because thiseventTypeWithBrokerAsReference
is a new function that I added in this PR, it hasn't been merged into the main branch. @creydrThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably, because you have to make
eventTypeWithBrokerAsReference
public