Skip to content

Commit 21b0a8d

Browse files
committed
Fix e2e tests
1 parent 50362c4 commit 21b0a8d

7 files changed

Lines changed: 34 additions & 13 deletions

File tree

authorizer/authorizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Authorizer interface {
99

1010
type AuthorizeCommandInput struct {
1111
Channel string
12-
Payload []byte
12+
Payload [][]byte
1313
}
1414

1515
type AuthorizeCommandOutput struct {

authorizer/iam.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func (authorizer *iam_authorizer) Authorize(ctx context.Context, input Authorize
4848
}
4949

5050
if input.Payload != nil {
51-
canonical.Payload = []string{string(input.Payload)}
51+
canonical.Payload = make([]string, len(input.Payload))
52+
for index, payload := range input.Payload {
53+
canonical.Payload[index] = string(payload)
54+
}
5255
}
5356

5457
payload, err := json.Marshal(canonical)

client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ func (client *appsync_client) Publish(ctx context.Context, input PublishCommandI
3030
authz = authorizer.NewInternalAdapter(input.Authorizer)
3131
}
3232
var output PublishCommandOutput
33+
payload := make([]app.Payload, len(input.Events))
34+
35+
for index, event := range input.Events {
36+
payload[index] = app.Payload(event)
37+
}
3338

3439
result, err := client.usecases.Publish.Publish(ctx, publish.PublishCommandInput{
3540
Destination: input.Channel,
36-
Payload: input.Payload,
41+
Events: payload,
3742
Frame: events.Publish(),
3843
Authorizer: authz,
3944
})

e2e/e2e_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ func TestAppSyncAuthorizers(t *testing.T) {
126126
}
127127
}()
128128

129-
if err := client.Publish(ctx, appsync.PublishCommandInput{
129+
if _, err := client.Publish(ctx, appsync.PublishCommandInput{
130130
Channel: channel,
131-
Payload: payload,
131+
Events: [][]byte{payload},
132132
}); err != nil {
133133
t.Fatalf("publish: %v", err)
134134
}
@@ -284,9 +284,9 @@ func TestPerRequestAuthorizerOverride(t *testing.T) {
284284
}
285285
}()
286286

287-
if err := client.Publish(ctx, appsync.PublishCommandInput{
287+
if _, err := client.Publish(ctx, appsync.PublishCommandInput{
288288
Channel: channel,
289-
Payload: payload,
289+
Events: [][]byte{payload},
290290
Authorizer: iam,
291291
}); err != nil {
292292
t.Fatalf("publish: %v", err)
@@ -356,9 +356,9 @@ func TestConnectionSpecificAuthorizers(t *testing.T) {
356356
}
357357
}()
358358

359-
if err := client.Publish(ctx, appsync.PublishCommandInput{
359+
if _, err := client.Publish(ctx, appsync.PublishCommandInput{
360360
Channel: channel,
361-
Payload: payload,
361+
Events: [][]byte{payload},
362362
}); err != nil {
363363
t.Fatalf("publish: %v", err)
364364
}
@@ -435,9 +435,9 @@ func TestMixedConnectionLevelAuthorizers(t *testing.T) {
435435
}
436436
}()
437437

438-
if err := client.Publish(ctx, appsync.PublishCommandInput{
438+
if _, err := client.Publish(ctx, appsync.PublishCommandInput{
439439
Channel: channel,
440-
Payload: payload,
440+
Events: [][]byte{payload},
441441
}); err != nil {
442442
t.Fatalf("publish: %v", err)
443443
}

internal/infrastructure/authorizer/public-adapter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ func NewInternalAdapter(public pub.Authorizer) *InternalAuthorizerAdapter {
1818
}
1919

2020
func (authorizer *InternalAuthorizerAdapter) Authorize(ctx context.Context, input app.AuthorizeCommandInput) (app.Signature, error) {
21+
payload := make([][]byte, len(input.Payload))
22+
for index := range input.Payload {
23+
payload[index] = []byte(input.Payload[index])
24+
}
25+
2126
output, err := authorizer.public.Authorize(ctx, pub.AuthorizeCommandInput{
2227
Channel: input.Channel,
23-
Payload: input.Payload,
28+
Payload: payload,
2429
})
2530

2631
if err != nil {

internal/infrastructure/events/builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,18 @@ func (builder *FrameBuilder) Build() app.Frame {
7171
} else {
7272
id = generate_id()
7373
}
74+
75+
payload := make([]string, len(builder.batch))
76+
77+
for index, event := range builder.batch {
78+
payload[index] = string(event)
79+
}
80+
7481
return Frame{
7582
Id: id,
7683
Topic: builder.channel,
7784
Signature: builder.signature,
78-
Payload: []string{string(builder.payload)},
85+
Payload: payload,
7986
Type: builder._type,
8087
}
8188
}

ports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Backpressure struct {
6363
type PublishCommandInput struct {
6464
Channel string
6565
Payload []byte
66+
Events [][]byte
6667
Authorizer authorizer.Authorizer
6768
}
6869

0 commit comments

Comments
 (0)