From 88d41e9954ce3eac720bdbb5f714a58e129b79b6 Mon Sep 17 00:00:00 2001 From: Benjamin Kaplan Date: Fri, 14 Feb 2020 10:36:08 -0800 Subject: [PATCH] Stop special-case unmarhalling json from pubsub. Instead, leave it in base64 like every other format. --- pkg/pubsub/adapter/converters/pubsub.go | 12 +----------- pkg/pubsub/adapter/converters/pubsub_test.go | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/pkg/pubsub/adapter/converters/pubsub.go b/pkg/pubsub/adapter/converters/pubsub.go index 45d5bc48ce..df0457ae27 100644 --- a/pkg/pubsub/adapter/converters/pubsub.go +++ b/pkg/pubsub/adapter/converters/pubsub.go @@ -18,7 +18,6 @@ package converters import ( "context" - "encoding/json" "time" cloudevents "github.com/cloudevents/sdk-go" @@ -60,16 +59,7 @@ func convertPubSub(ctx context.Context, msg *cepubsub.Message, sendMode ModeType ID: event.ID(), Attributes: msg.Attributes, PublishTime: event.Time(), - } - - var raw json.RawMessage - if err := event.DataAs(&raw); err != nil { - logger.Desugar().Debug("Failed to get data as raw json, using as is.", zap.Error(err)) - // Use data as a byte slice. - msg.Data = event.Data - } else { - // Use data as a raw message. - msg.Data = raw + Data: event.Data, } if err := event.SetData(&PushMessage{ diff --git a/pkg/pubsub/adapter/converters/pubsub_test.go b/pkg/pubsub/adapter/converters/pubsub_test.go index 4d57724c78..d502019256 100644 --- a/pkg/pubsub/adapter/converters/pubsub_test.go +++ b/pkg/pubsub/adapter/converters/pubsub_test.go @@ -116,7 +116,7 @@ func TestConvertCloudPubSub(t *testing.T) { return pubSubPushCloudEvent(map[string]string{ "attribute1": "value1", "Invalid-Attrib#$^": "value2", - }, "\"test data\"") + }, "\"InRlc3QgZGF0YSI=\"") }, }, { name: "Push mode with no attributes", @@ -126,7 +126,7 @@ func TestConvertCloudPubSub(t *testing.T) { }, sendMode: Push, wantEventFn: func() *cloudevents.Event { - return pubSubPushCloudEvent(nil, "\"test data\"") + return pubSubPushCloudEvent(nil, "\"InRlc3QgZGF0YSI=\"") }, }}