forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leverage new subscriber image endpoints in external-solution test (ky…
…ma-project#9354) * Changed the endpoint the lambda function posts to * Update readme * Combine steps for sending and checking the event Add a counter to differentiate each event by its id Retrieve event via ID If retrieving by ID fails get and print all received events to facilitate debugging * Fix imports formatting * Changes based on PR review * Changes based on PR review * Fix imports formatting * Refactor send event struct * Remove sendEvent field name
- Loading branch information
1 parent
c77032c
commit 415d688
Showing
11 changed files
with
328 additions
and
38 deletions.
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
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
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
12 changes: 12 additions & 0 deletions
12
tests/end-to-end/external-solution-integration/pkg/testkit/send_event.go
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,12 @@ | ||
package testkit | ||
|
||
type SendEvent struct { | ||
State SendEventState | ||
AppName string | ||
Payload string | ||
} | ||
|
||
// SendEventState represents SendEvent dependencies | ||
type SendEventState interface { | ||
GetEventSender() *EventSender | ||
} |
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
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
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
91 changes: 91 additions & 0 deletions
91
...solution-integration/pkg/testsuite/send_event_to_compatibility_layer_and_check_eventId.go
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,91 @@ | ||
package testsuite | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
retrygo "github.com/avast/retry-go" | ||
"github.com/kyma-project/kyma/tests/end-to-end/external-solution-integration/internal/example_schema" | ||
"github.com/kyma-project/kyma/tests/end-to-end/external-solution-integration/pkg/retry" | ||
"github.com/kyma-project/kyma/tests/end-to-end/external-solution-integration/pkg/step" | ||
"github.com/kyma-project/kyma/tests/end-to-end/external-solution-integration/pkg/testkit" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// SendEventToCompatibilityLayerAndCheckEventId is a step which sends an event and checks if the correct EventId has been received | ||
type SendEventToCompatibilityLayerAndCheckEventId struct { | ||
testkit.SendEvent | ||
counter int | ||
testService *testkit.TestService | ||
retryOpts []retrygo.Option | ||
} | ||
|
||
var _ step.Step = &SendEventToCompatibilityLayerAndCheckEventId{} | ||
|
||
// NewSendEventToCompatibilityLayerAndCheckEventId returns new SendEventToCompatibilityLayerAndCheckEventId | ||
func NewSendEventToCompatibilityLayerAndCheckEventId(appName, payload string, state testkit.SendEventState, testService *testkit.TestService, | ||
opts ...retrygo.Option) *SendEventToCompatibilityLayerAndCheckEventId { | ||
return &SendEventToCompatibilityLayerAndCheckEventId{ | ||
testkit.SendEvent{State: state, AppName: appName, Payload: payload}, | ||
0, | ||
testService, | ||
opts, | ||
} | ||
} | ||
|
||
// Name returns name of the step | ||
func (s *SendEventToCompatibilityLayerAndCheckEventId) Name() string { | ||
return "Send event to compatibility layer and check event id" | ||
} | ||
|
||
// Run executes the step | ||
func (s *SendEventToCompatibilityLayerAndCheckEventId) Run() error { | ||
const basicId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa" | ||
eventId := fmt.Sprint(basicId, s.counter) | ||
|
||
err := s.sendEventToCompatibilityLayer(eventId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.checkEventId(eventId) | ||
if err != nil { | ||
s.counter++ | ||
return errors.Wrap(err, s.testService.DumpAllReceivedEvents().Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Cleanup removes all resources that may possibly created by the step | ||
func (s *SendEventToCompatibilityLayerAndCheckEventId) Cleanup() error { | ||
return nil | ||
} | ||
|
||
func (s *SendEventToCompatibilityLayerAndCheckEventId) checkEventId(eventId string) error { | ||
err := retry.Do(func() error { | ||
return s.testService.CheckEventId(eventId) | ||
}, s.retryOpts...) | ||
|
||
return err | ||
} | ||
|
||
func (s *SendEventToCompatibilityLayerAndCheckEventId) sendEventToCompatibilityLayer(eventId string) error { | ||
event := s.prepareEvent(eventId) | ||
err := s.State.GetEventSender().SendEventToCompatibilityLayer(s.AppName, event) | ||
logrus.WithField("component", "SendEventToCompatibilityLayer").Debugf("SendCloudEventToCompatibilityLayer: eventID: %v; error: %v", eventId, err) | ||
|
||
return err | ||
} | ||
|
||
func (s *SendEventToCompatibilityLayerAndCheckEventId) prepareEvent(eventId string) *testkit.ExampleEvent { | ||
return &testkit.ExampleEvent{ | ||
EventType: example_schema.EventType, | ||
EventTypeVersion: example_schema.EventVersion, | ||
EventID: eventId, | ||
EventTime: time.Now(), | ||
Data: s.Payload, | ||
} | ||
} |
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
Oops, something went wrong.