From 49ce3f31fbcdf1293f2ebbd139b4aea8264ca7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Ma=C5=BEgon?= Date: Wed, 28 Feb 2024 19:59:05 +0100 Subject: [PATCH] fix linter errors --- opencdc/data.go | 2 ++ opencdc/serializer.go | 7 ++++++- opencdc/serializer_test.go | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/opencdc/data.go b/opencdc/data.go index 962fb0d..f8b787f 100644 --- a/opencdc/data.go +++ b/opencdc/data.go @@ -88,8 +88,10 @@ func (d RawData) Clone() Data { func (d RawData) MarshalJSON(ctx context.Context) ([]byte, error) { if ctx != nil { s := ctx.Value(jsonMarshalOptionsCtxKey{}) + //nolint:forcetypeassert // We know the type of the value. if s != nil && s.(*JSONMarshalOptions).RawDataAsString { // We should serialize RawData as a string. + //nolint:wrapcheck // If we didn't implement MarshalJSON this would be done by the json package. return json.Marshal(string(d)) } } diff --git a/opencdc/serializer.go b/opencdc/serializer.go index d2e4879..c75d64b 100644 --- a/opencdc/serializer.go +++ b/opencdc/serializer.go @@ -16,6 +16,7 @@ package opencdc import ( "context" + "fmt" "github.com/goccy/go-json" ) @@ -38,5 +39,9 @@ func (s JSONSerializer) Serialize(r Record) ([]byte, error) { // instead of pointer. s = JSONSerializer{} }() - return json.MarshalContext(ctx, r) + bytes, err := json.MarshalContext(ctx, r) + if err != nil { + return nil, fmt.Errorf("failed to serialize record to JSON: %w", err) + } + return bytes, nil } diff --git a/opencdc/serializer_test.go b/opencdc/serializer_test.go index fac3c26..f1c6e58 100644 --- a/opencdc/serializer_test.go +++ b/opencdc/serializer_test.go @@ -22,8 +22,6 @@ import ( ) func TestJSONSerializer(t *testing.T) { - t.Skip() - is := is.New(t) rec := Record{ Position: Position("standing"), Operation: OperationUpdate, @@ -62,6 +60,7 @@ func TestJSONSerializer(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + is := is.New(t) rec.SetSerializer(tc.serializer) b := rec.Bytes() is.Equal(cmp.Diff(string(b), tc.want), "")