From 3638af885cfe1cc7dd7421d23ebe4dbf278d1937 Mon Sep 17 00:00:00 2001 From: Francesco Guardiani Date: Wed, 8 Apr 2020 22:07:02 +0200 Subject: [PATCH] Hotfix for MessageWrapper (#449) Signed-off-by: Francesco Guardiani --- v2/binding/buffering/acks_before_finish_message.go | 4 ++-- .../buffering/acks_before_finish_message_test.go | 11 +++++++++++ v2/binding/finish_message.go | 4 ++-- v2/binding/finish_message_test.go | 12 ++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/v2/binding/buffering/acks_before_finish_message.go b/v2/binding/buffering/acks_before_finish_message.go index 103c9b388..4e7a33f0b 100644 --- a/v2/binding/buffering/acks_before_finish_message.go +++ b/v2/binding/buffering/acks_before_finish_message.go @@ -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 { diff --git a/v2/binding/buffering/acks_before_finish_message_test.go b/v2/binding/buffering/acks_before_finish_message_test.go index 0bcecb03e..437ce2985 100644 --- a/v2/binding/buffering/acks_before_finish_message_test.go +++ b/v2/binding/buffering/acks_before_finish_message_test.go @@ -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" ) @@ -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")) +} diff --git a/v2/binding/finish_message.go b/v2/binding/finish_message.go index d1b5b8778..17445bfe5 100644 --- a/v2/binding/finish_message.go +++ b/v2/binding/finish_message.go @@ -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 { diff --git a/v2/binding/finish_message_test.go b/v2/binding/finish_message_test.go index 1ec24b237..9abb9908c 100644 --- a/v2/binding/finish_message_test.go +++ b/v2/binding/finish_message_test.go @@ -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" ) @@ -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")) +}