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

chore: remove subscription v1alpha1 tests #530

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 0 additions & 36 deletions hack/e2e/common/eventing/testsubscriptioninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eventing
import (
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

eventingv1alpha1 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
)

Expand All @@ -14,41 +13,6 @@ type TestSubscriptionInfo struct {
Types []string
}

func (s TestSubscriptionInfo) V1Alpha1SpecFilters() []*eventingv1alpha1.EventMeshFilter {
var filters []*eventingv1alpha1.EventMeshFilter
for _, etype := range s.Types {
filter := &eventingv1alpha1.EventMeshFilter{
EventSource: &eventingv1alpha1.Filter{
Type: "exact",
Property: "source",
Value: "",
},
EventType: &eventingv1alpha1.Filter{
Type: "exact",
Property: "type",
Value: etype,
},
}
filters = append(filters, filter)
}
return filters
}

func (s TestSubscriptionInfo) ToSubscriptionV1Alpha1(sink, namespace string) *eventingv1alpha1.Subscription {
return &eventingv1alpha1.Subscription{
ObjectMeta: kmetav1.ObjectMeta{
Name: s.Name,
Namespace: namespace,
},
Spec: eventingv1alpha1.SubscriptionSpec{
Sink: sink,
Filter: &eventingv1alpha1.BEBFilters{
Filters: s.V1Alpha1SpecFilters(),
},
},
}
}

func (s TestSubscriptionInfo) ToSubscriptionV1Alpha2(sink, namespace string) *eventingv1alpha2.Subscription {
return &eventingv1alpha2.Subscription{
ObjectMeta: kmetav1.ObjectMeta{
Expand Down
26 changes: 0 additions & 26 deletions hack/e2e/common/eventing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ func CloudEventData(source, eventType string, encoding binding.Encoding) map[str
return map[string]interface{}{keyApp: source, keyMode: CloudEventMode(encoding), keyType: eventType}
}

func ExtractSourceFromSubscriptionV1Alpha1Type(eventType string) string {
segments := strings.Split(eventType, ".")
return segments[3]
}

func ExtractLegacyTypeFromSubscriptionV1Alpha1Type(eventTypePrefix, eventSource, eventVersion, eventType string) string {
tmp := strings.TrimPrefix(eventType, fmt.Sprintf("%s.%s.", eventTypePrefix, eventSource))
return strings.TrimSuffix(tmp, fmt.Sprintf(".%s", eventVersion))
}

func ExtractLegacyTypeFromSubscriptionV1Alpha2Type(eventVersion, eventType string) string {
return strings.TrimSuffix(eventType, fmt.Sprintf(".%s", eventVersion))
}
Expand All @@ -55,22 +45,6 @@ func ExtractVersionFromEventType(eventType string) string {
return segments[len(segments)-1]
}

func NewLegacyEventForV1Alpha1(eventType, eventTypePrefix string) (string, string, string, string) {
// If the eventType is sap.kyma.custom.noapp.order.created.v1, then for legacy event:
// eventSource should be: noapp
// eventType should be: order.created
// eventVersion should be: v1
eventID := uuid.New().String()
eventSource := ExtractSourceFromSubscriptionV1Alpha1Type(eventType)
eventVersion := ExtractVersionFromEventType(eventType)
legacyEventType := ExtractLegacyTypeFromSubscriptionV1Alpha1Type(eventTypePrefix,
eventSource, eventVersion, eventType)
eventData := LegacyEventData(eventSource, legacyEventType)
payload := LegacyEventPayload(eventID, eventVersion, legacyEventType, eventData)

return eventID, eventSource, legacyEventType, payload
}

func NewLegacyEvent(eventSource, eventType string) (string, string, string, string) {
// If the eventType is order.created.v1 and source is noapp, then for legacy event:
// eventSource should be: noapp
Expand Down
24 changes: 0 additions & 24 deletions hack/e2e/common/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const (
type SubscriptionCRVersion string

const (
V1Alpha1SubscriptionCRVersion SubscriptionCRVersion = "v1alpha1"
V1Alpha2SubscriptionCRVersion SubscriptionCRVersion = "v1alpha2"
)

Expand Down Expand Up @@ -119,29 +118,6 @@ func PublisherSpec() operatorv1alpha1.Publisher {
}
}

func V1Alpha1SubscriptionsToTest() []eventing.TestSubscriptionInfo {
return []eventing.TestSubscriptionInfo{
{
Name: "test-sub-1-v1alpha1",
Description: "event type and source without any alpha-numeric characters",
Types: []string{"sap.kyma.custom.noapp.order.tested.v1"},
},
{
Name: "test-sub-2-v1alpha1",
Description: "event type and source with alpha-numeric characters",
Types: []string{"sap.kyma.custom.test-app.order-$.second.R-e-c-e-i-v-e-d.v1"},
},
{
Name: "test-sub-3-with-multiple-types-v1alpha1",
Description: "multiple types in same subscription",
Types: []string{
"sap.kyma.custom.connected-app.order.tested.v1",
"sap.kyma.custom.connected-app2.or-der.crea-ted.one.two.three.v4",
},
},
}
}

func V1Alpha2SubscriptionsToTest() []eventing.TestSubscriptionInfo {
return []eventing.TestSubscriptionInfo{
{
Expand Down
9 changes: 1 addition & 8 deletions hack/e2e/common/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
"os"
"path/filepath"

natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"

eventingv1alpha1 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha1"
eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2"
operatorv1alpha1 "github.com/kyma-project/eventing-manager/api/operator/v1alpha1"
natsv1alpha1 "github.com/kyma-project/nats-manager/api/v1alpha1"
)

func GetK8sClients() (*kubernetes.Clientset, client.Client, *dynamic.DynamicClient, error) {
Expand Down Expand Up @@ -48,12 +47,6 @@ func GetK8sClients() (*kubernetes.Clientset, client.Client, *dynamic.DynamicClie
return nil, nil, nil, err
}

// add Subscription v1alpha1 CRD to the scheme.
err = eventingv1alpha1.AddToScheme(scheme.Scheme)
if err != nil {
return nil, nil, nil, err
}

// add Subscription v1alpha2 CRD to the scheme.
err = eventingv1alpha2.AddToScheme(scheme.Scheme)
if err != nil {
Expand Down
51 changes: 3 additions & 48 deletions hack/e2e/common/testenvironment/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,11 @@ func (te *TestEnvironment) InitSinkClient() error {
}

func (te *TestEnvironment) CreateAllSubscriptions() error {
ctx := context.TODO()
// Create v1alpha1 subscriptions if not exists.
err := te.CreateV1Alpha1Subscriptions(ctx, fixtures.V1Alpha1SubscriptionsToTest())
if err != nil {
return err
}

// Create v1alpha2 subscriptions if not exists.
return te.CreateV1Alpha2Subscriptions(ctx, fixtures.V1Alpha2SubscriptionsToTest())
return te.CreateV1Alpha2Subscriptions(context.TODO(), fixtures.V1Alpha2SubscriptionsToTest())
}

func (te *TestEnvironment) DeleteAllSubscriptions() error {
// delete v1alpha1 subscriptions if not exists.
for _, subToTest := range fixtures.V1Alpha1SubscriptionsToTest() {
if err := te.DeleteSubscriptionFromK8s(subToTest.Name, te.TestConfigs.TestNamespace); err != nil {
return err
}
}

// Delete v1alpha2 subscriptions if not exists.
for _, subToTest := range fixtures.V1Alpha2SubscriptionsToTest() {
if err := te.DeleteSubscriptionFromK8s(subToTest.Name, te.TestConfigs.TestNamespace); err != nil {
Expand All @@ -166,29 +152,8 @@ func (te *TestEnvironment) DeleteAllSubscriptions() error {
}

func (te *TestEnvironment) WaitForAllSubscriptions() error {
ctx := context.TODO()
// Wait for v1alpha1 subscriptions to get ready.
err := te.WaitForSubscriptions(ctx, fixtures.V1Alpha1SubscriptionsToTest())
if err != nil {
return err
}

// wait for v1alpha2 subscriptions to get ready
return te.WaitForSubscriptions(ctx, fixtures.V1Alpha1SubscriptionsToTest())
}

func (te *TestEnvironment) CreateV1Alpha1Subscriptions(ctx context.Context, subList []eventing.TestSubscriptionInfo) error {
for _, subInfo := range subList {
err := common.Retry(FewAttempts, SmallInterval, func() error {
newSub := subInfo.ToSubscriptionV1Alpha1(te.TestConfigs.SubscriptionSinkURL, te.TestConfigs.TestNamespace)
return client.IgnoreAlreadyExists(te.K8sClient.Create(ctx, newSub))
})
// Return error if all retries are exhausted.
if err != nil {
return err
}
}
return nil
return te.WaitForSubscriptions(context.TODO(), fixtures.V1Alpha2SubscriptionsToTest())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix.

}

func (te *TestEnvironment) CreateV1Alpha2Subscriptions(ctx context.Context, subList []eventing.TestSubscriptionInfo) error {
Expand Down Expand Up @@ -383,12 +348,7 @@ func (te *TestEnvironment) DeleteSubscriptionFromK8s(name, namespace string) err

func (te *TestEnvironment) TestDeliveryOfLegacyEvent(eventSource, eventType string, subCRVersion fixtures.SubscriptionCRVersion) error {
// define the event
var evntID, legacyEventSource, legacyEventType, payload string
if subCRVersion == fixtures.V1Alpha1SubscriptionCRVersion {
evntID, legacyEventSource, legacyEventType, payload = eventing.NewLegacyEventForV1Alpha1(eventType, te.TestConfigs.EventTypePrefix)
} else {
evntID, legacyEventSource, legacyEventType, payload = eventing.NewLegacyEvent(eventSource, eventType)
}
evntID, legacyEventSource, legacyEventType, payload := eventing.NewLegacyEvent(eventSource, eventType)

// publish the event
if err := te.EventPublisher.SendLegacyEventWithRetries(legacyEventSource, legacyEventType, payload, FewAttempts, Interval); err != nil {
Expand Down Expand Up @@ -473,11 +433,6 @@ func (te *TestEnvironment) CompareCloudEvents(expectedEvent cloudevents.Event, g
resultError = fixtures.AppendMsgToError(resultError, msg)
}

// if it is a v1alpha1 Subscription event, then we do not check further.
if strings.HasPrefix(gotEvent.Type(), te.TestConfigs.EventTypePrefix) {
return resultError
}

// check in detail further the source and type.
if expectedEvent.Source() != gotEvent.Source() {
msg := fmt.Sprintf("expected event Source: %s, got event Source: %s", expectedEvent.Source(), gotEvent.Source())
Expand Down
20 changes: 0 additions & 20 deletions hack/e2e/eventing/delivery/delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,12 @@ func TestMain(m *testing.M) {

// ++ Tests

func Test_LegacyEvents_SubscriptionV1Alpha1(t *testing.T) {
t.Parallel()
// binding.EncodingUnknown means legacy event.
testEventDelivery(t, LegacyEventCase, fixtures.V1Alpha1SubscriptionsToTest(), binding.EncodingUnknown, fixtures.V1Alpha1SubscriptionCRVersion)
}

func Test_LegacyEvents(t *testing.T) {
t.Parallel()
// binding.EncodingUnknown means legacy event.
testEventDelivery(t, LegacyEventCase, fixtures.V1Alpha2SubscriptionsToTest(), binding.EncodingUnknown, fixtures.V1Alpha2SubscriptionCRVersion)
}

func Test_StructuredCloudEvents_SubscriptionV1Alpha1(t *testing.T) {
t.Parallel()
testEventDelivery(t, StructuredCloudEventCase, fixtures.V1Alpha1SubscriptionsToTest(), binding.EncodingStructured, fixtures.V1Alpha1SubscriptionCRVersion)
}

func Test_BinaryCloudEvents_SubscriptionV1Alpha1(t *testing.T) {
t.Parallel()
testEventDelivery(t, BinaryCloudEventCase, fixtures.V1Alpha1SubscriptionsToTest(), binding.EncodingBinary, fixtures.V1Alpha1SubscriptionCRVersion)
}

func Test_StructuredCloudEvents(t *testing.T) {
t.Parallel()
testEventDelivery(t, StructuredCloudEventCase, fixtures.V1Alpha2SubscriptionsToTest(), binding.EncodingStructured, fixtures.V1Alpha2SubscriptionCRVersion)
Expand Down Expand Up @@ -110,10 +94,6 @@ func testEventDelivery(t *testing.T,

// given
eventSourceToUse := subToTest.Source
if subCRVersion == fixtures.V1Alpha1SubscriptionCRVersion {
// For EventMesh with Subscription v1alpha1, the eventSource should be EventMesh NameSpace.
eventSourceToUse = testEnvironment.TestConfigs.EventMeshNamespace
}

// when
err := common.Retry(testenvironment.ThreeAttempts, testenvironment.Interval, func() error {
Expand Down
Loading