-
Notifications
You must be signed in to change notification settings - Fork 592
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] Introduce --namespace test flag and randomize test object names #3313
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,11 @@ type eventTestCase struct { | |
Type string | ||
Source string | ||
Extensions map[string]interface{} | ||
NameSuffix string | ||
} | ||
|
||
// ToString converts the test case to a string to create names for different objects (e.g., triggers, services, etc.). | ||
func (tc eventTestCase) String() string { | ||
func (tc eventTestCase) Data() string { | ||
eventType := tc.Type | ||
eventSource := tc.Source | ||
extensions := tc.Extensions | ||
|
@@ -57,11 +58,15 @@ func (tc eventTestCase) String() string { | |
u, _ := url.Parse(eventSource) | ||
eventSource = strings.Split(u.Host, ".")[0] | ||
} | ||
name := strings.ToLower(fmt.Sprintf("%s-%s", eventType, eventSource)) | ||
data := strings.ToLower(fmt.Sprintf("%s-%s", eventType, eventSource)) | ||
if len(extensions) > 0 { | ||
name = strings.ToLower(fmt.Sprintf("%s-%s", name, extensionsToString(extensions))) | ||
data = strings.ToLower(fmt.Sprintf("%s-%s", data, extensionsToString(extensions))) | ||
} | ||
return name | ||
return data | ||
} | ||
|
||
func (tc eventTestCase) Name() string { | ||
return fmt.Sprintf("%s%s", tc.Data(), tc.NameSuffix) | ||
} | ||
|
||
// ToEventMatcher converts the test case to the event matcher | ||
|
@@ -97,7 +102,7 @@ type BrokerCreator func(client *testlib.Client) string | |
// ChannelBasedBrokerCreator creates a BrokerCreator that creates a broker based on the channel parameter. | ||
func ChannelBasedBrokerCreator(channel metav1.TypeMeta, brokerClass string) BrokerCreator { | ||
return func(client *testlib.Client) string { | ||
brokerName := strings.ToLower(channel.Kind) | ||
brokerName := testlib.NameForTest(channel.Kind) | ||
|
||
// create a ConfigMap used by the broker. | ||
config := client.CreateBrokerConfigMapOrFail("config-"+brokerName, &channel) | ||
|
@@ -155,10 +160,10 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
{Type: eventType2, Source: eventSource2}, | ||
}, | ||
eventFilters: []eventTestCase{ | ||
{Type: any, Source: any}, | ||
{Type: eventType1, Source: any}, | ||
{Type: any, Source: eventSource1}, | ||
{Type: eventType1, Source: eventSource1}, | ||
{Type: any, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
}, | ||
deprecatedTriggerFilter: true, | ||
}, { | ||
|
@@ -170,10 +175,10 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
{Type: eventType2, Source: eventSource2}, | ||
}, | ||
eventFilters: []eventTestCase{ | ||
{Type: any, Source: any}, | ||
{Type: eventType1, Source: any}, | ||
{Type: any, Source: eventSource1}, | ||
{Type: eventType1, Source: eventSource1}, | ||
{Type: any, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
}, | ||
deprecatedTriggerFilter: false, | ||
}, { | ||
|
@@ -185,10 +190,10 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
{Type: eventType2, Source: eventSource2}, | ||
}, | ||
eventFilters: []eventTestCase{ | ||
{Type: any, Source: any}, | ||
{Type: eventType1, Source: any}, | ||
{Type: any, Source: eventSource1}, | ||
{Type: eventType1, Source: eventSource1}, | ||
{Type: any, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: any, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: eventSource1, NameSuffix: lib.RandomSuffix()}, | ||
}, | ||
deprecatedTriggerFilter: false, | ||
v1beta1: true, | ||
|
@@ -205,18 +210,19 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
{Type: eventType2, Source: eventSource2, Extensions: map[string]interface{}{extensionName1: extensionValue1, nonMatchingExtensionName: extensionValue2}}, | ||
}, | ||
eventFilters: []eventTestCase{ | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1}}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1, extensionName2: extensionValue2}}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName2: extensionValue2}}, | ||
{Type: eventType1, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1}}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: any}}, | ||
{Type: any, Source: eventSource1, Extensions: map[string]interface{}{extensionName1: extensionValue1}}, | ||
{Type: any, Source: eventSource1, Extensions: map[string]interface{}{extensionName1: extensionValue1, extensionName2: extensionValue2}}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1, extensionName2: extensionValue2}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName2: extensionValue2}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: eventType1, Source: any, Extensions: map[string]interface{}{extensionName1: extensionValue1}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: any, Extensions: map[string]interface{}{extensionName1: any}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: eventSource1, Extensions: map[string]interface{}{extensionName1: extensionValue1}, NameSuffix: lib.RandomSuffix()}, | ||
{Type: any, Source: eventSource1, Extensions: map[string]interface{}{extensionName1: extensionValue1, extensionName2: extensionValue2}, NameSuffix: lib.RandomSuffix()}, | ||
}, | ||
deprecatedTriggerFilter: false, | ||
}, | ||
} | ||
for _, test := range tests { | ||
test := test // Prevent race conditions when running in parallel. | ||
t.Run(test.name, func(t *testing.T) { | ||
client := testlib.Setup(t, true) | ||
defer testlib.TearDown(client) | ||
|
@@ -245,7 +251,7 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
eventTrackers := make(map[string]*recordevents.EventInfoStore, len(test.eventFilters)) | ||
for _, event := range test.eventFilters { | ||
// Create event recorder pod and service | ||
subscriberName := "dumper-" + event.String() | ||
subscriberName := event.Name() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we remove the ninjaedit: maybe we can do something similar to your sender change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it because the names need to be created in advance, and if I then prefix it with "dumper-" it may exceed the 63 limit, plus I'm getting segmentation faults because eventTrackers then don't include the right matcher and it calls a function on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now I'm facing a problem with running tests in parallel. Some of them label namespaces with |
||
eventRecordPod := resources.EventRecordPod(subscriberName) | ||
client.CreatePodOrFail(eventRecordPod, testlib.WithService(subscriberName)) | ||
eventTracker, err := recordevents.NewEventInfoStore(client, subscriberName) | ||
|
@@ -256,7 +262,7 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
defer eventTracker.Cleanup() | ||
|
||
// Create trigger. | ||
triggerName := "trigger-" + event.String() | ||
triggerName := event.Name() | ||
client.CreateTriggerOrFailV1Beta1(triggerName, | ||
resources.WithSubscriberServiceRefForTriggerV1Beta1(subscriberName), | ||
resources.WithAttributesTriggerFilterV1Beta1(event.Source, event.Type, event.Extensions), | ||
|
@@ -284,13 +290,13 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
eventToSend.SetExtension(k, v) | ||
} | ||
|
||
data := fmt.Sprintf(`{"msg":"%s"}`, eventTestCase.String()) | ||
data := fmt.Sprintf(`{"msg":"%s"}`, eventTestCase.Data()) | ||
if err := eventToSend.SetData(cloudevents.ApplicationJSON, []byte(data)); err != nil { | ||
t.Fatalf("Cannot set the payload of the event: %s", err.Error()) | ||
} | ||
|
||
// Send event | ||
senderPodName := "sender-" + eventTestCase.String() | ||
senderPodName := testlib.NameForTest("sender-" + eventTestCase.Data()) | ||
client.SendEventToAddressable(senderPodName, brokerName, testlib.BrokerTypeMeta, eventToSend) | ||
|
||
// Sent event matcher | ||
|
@@ -301,7 +307,7 @@ func TestBrokerWithManyTriggers(t *testing.T, brokerCreator BrokerCreator, shoul | |
|
||
// Check on every dumper whether we should expect this event or not | ||
for _, eventFilter := range test.eventFilters { | ||
subscriberName := "dumper-" + eventFilter.String() | ||
subscriberName := eventFilter.Name() | ||
|
||
if eventFilter.ToEventMatcher()(eventToSend) == nil { | ||
// This filter should match this event | ||
|
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.
It seems the comment on line 46 was forgotten to be updated?