Skip to content

Commit

Permalink
Hotfix for MessageWrapper (#449)
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper authored Apr 8, 2020
1 parent 4a880eb commit 3638af8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions v2/binding/buffering/acks_before_finish_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type acksMessage struct {
}

func (m *acksMessage) GetAttribute(k spec.Kind) (spec.Attribute, interface{}) {
return binding.MessageMetadataReader(m).GetAttribute(k)
return m.Message.(binding.MessageMetadataReader).GetAttribute(k)
}

func (m *acksMessage) GetExtension(s string) interface{} {
return binding.MessageMetadataReader(m).GetExtension(s)
return m.Message.(binding.MessageMetadataReader).GetExtension(s)
}

func (m *acksMessage) GetWrappedMessage() binding.Message {
Expand Down
11 changes: 11 additions & 0 deletions v2/binding/buffering/acks_before_finish_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/cloudevents/sdk-go/v2/binding"
"github.com/cloudevents/sdk-go/v2/binding/spec"
"github.com/cloudevents/sdk-go/v2/binding/test"
"github.com/cloudevents/sdk-go/v2/event"
"github.com/cloudevents/sdk-go/v2/types"
)
Expand Down Expand Up @@ -77,3 +79,12 @@ func TestCopyAndWithAcksBeforeFinish(t *testing.T) {
wg.Wait()
require.True(t, finishCalled)
}

func TestMessageMetadataHandler(t *testing.T) {
var testEvent = test.FullEvent()
finishMessage := WithAcksBeforeFinish((*binding.EventMessage)(&testEvent), 3)

_, ty := finishMessage.(binding.MessageMetadataReader).GetAttribute(spec.Type)
require.Equal(t, testEvent.Type(), ty)
require.Equal(t, testEvent.Extensions()["exstring"], finishMessage.(binding.MessageMetadataReader).GetExtension("exstring"))
}
4 changes: 2 additions & 2 deletions v2/binding/finish_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ type finishMessage struct {
}

func (m *finishMessage) GetAttribute(k spec.Kind) (spec.Attribute, interface{}) {
return MessageMetadataReader(m).GetAttribute(k)
return m.Message.(MessageMetadataReader).GetAttribute(k)
}

func (m *finishMessage) GetExtension(s string) interface{} {
return MessageMetadataReader(m).GetExtension(s)
return m.Message.(MessageMetadataReader).GetExtension(s)
}

func (m *finishMessage) GetWrappedMessage() Message {
Expand Down
12 changes: 12 additions & 0 deletions v2/binding/finish_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cloudevents/sdk-go/v2/binding"
"github.com/cloudevents/sdk-go/v2/binding/spec"
"github.com/cloudevents/sdk-go/v2/binding/test"
"github.com/cloudevents/sdk-go/v2/event"
"github.com/cloudevents/sdk-go/v2/types"
)
Expand All @@ -33,3 +36,12 @@ func TestWithFinish(t *testing.T) {
assert.NoError(t, m.Finish(nil))
assert.NoError(t, <-done)
}

func TestMessageMetadataHandler(t *testing.T) {
var testEvent = test.FullEvent()
finishMessage := binding.WithFinish((*binding.EventMessage)(&testEvent), func(err error) {})

_, ty := finishMessage.(binding.MessageMetadataReader).GetAttribute(spec.Type)
require.Equal(t, testEvent.Type(), ty)
require.Equal(t, testEvent.Extensions()["exstring"], finishMessage.(binding.MessageMetadataReader).GetExtension("exstring"))
}

0 comments on commit 3638af8

Please sign in to comment.