From 3f2a7cf72d9b19691a20eaf55512557da98950eb Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Tue, 22 Oct 2024 22:02:47 +0200 Subject: [PATCH] cleanup --- cmd/connector/main.go | 4 --- source/logrepl/internal/relationset_test.go | 9 ++---- source/types/time.go | 31 --------------------- source/types/types.go | 9 ------ source/types/types_test.go | 26 ----------------- 5 files changed, 3 insertions(+), 76 deletions(-) delete mode 100644 source/types/time.go diff --git a/cmd/connector/main.go b/cmd/connector/main.go index 656cce0..a42940d 100644 --- a/cmd/connector/main.go +++ b/cmd/connector/main.go @@ -16,13 +16,9 @@ package main import ( postgres "github.com/conduitio/conduit-connector-postgres" - "github.com/conduitio/conduit-connector-postgres/source/types" sdk "github.com/conduitio/conduit-connector-sdk" ) func main() { - // Running as standalone plugin - types.WithBuiltinPlugin = false - sdk.Serve(postgres.Connector) } diff --git a/source/logrepl/internal/relationset_test.go b/source/logrepl/internal/relationset_test.go index b3d0399..97721dd 100644 --- a/source/logrepl/internal/relationset_test.go +++ b/source/logrepl/internal/relationset_test.go @@ -23,7 +23,6 @@ import ( "testing" "time" - "github.com/conduitio/conduit-connector-postgres/source/types" "github.com/conduitio/conduit-connector-postgres/test" "github.com/google/go-cmp/cmp" "github.com/jackc/pglogrepl" @@ -96,11 +95,9 @@ func TestRelationSetAllTypes(t *testing.T) { t.Run("with standalone plugin", func(t *testing.T) { is := is.New(t) - types.WithBuiltinPlugin = false values, err := rs.Values(ins.RelationID, ins.Tuple) is.NoErr(err) isValuesAllTypesStandalone(is, values) - types.WithBuiltinPlugin = true }) } @@ -383,7 +380,7 @@ func isValuesAllTypesStandalone(is *is.I, got map[string]any) { R: 13, Valid: true, }, - "col_date": time.Date(2022, 3, 14, 0, 0, 0, 0, time.UTC).UTC().String(), + "col_date": time.Date(2022, 3, 14, 0, 0, 0, 0, time.UTC).UTC(), "col_float4": float32(15), "col_float8": float64(16.16), "col_inet": netip.MustParsePrefix("192.168.0.17/32"), @@ -436,8 +433,8 @@ func isValuesAllTypesStandalone(is *is.I, got map[string]any) { Valid: true, }, "col_timetz": "04:05:06.789-08", - "col_timestamp": time.Date(2022, 3, 14, 15, 16, 17, 0, time.UTC).UTC().String(), - "col_timestamptz": time.Date(2022, 3, 14, 15+8, 16, 17, 0, time.UTC).UTC().String(), + "col_timestamp": time.Date(2022, 3, 14, 15, 16, 17, 0, time.UTC).UTC(), + "col_timestamptz": time.Date(2022, 3, 14, 15+8, 16, 17, 0, time.UTC).UTC(), "col_tsquery": "'fat' & ( 'rat' | 'cat' )", "col_tsvector": "'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'", "col_uuid": "bd94ee0b-564f-4088-bf4e-8d5e626caf66", // [16]uint8{0xbd, 0x94, 0xee, 0x0b, 0x56, 0x4f, 0x40, 0x88, 0xbf, 0x4e, 0x8d, 0x5e, 0x62, 0x6c, 0xaf, 0x66} diff --git a/source/types/time.go b/source/types/time.go deleted file mode 100644 index 8f5de84..0000000 --- a/source/types/time.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2022 Meroxa, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "time" -) - -type TimeFormatter struct{} - -// Format returns: -// * string format of Time when connector is not builtin -// * time type in UTC when connector is builtin -func (n TimeFormatter) Format(t time.Time) (any, error) { - if WithBuiltinPlugin { - return t.UTC(), nil - } - return t.UTC().String(), nil -} diff --git a/source/types/types.go b/source/types/types.go index e8f537a..5f826fa 100644 --- a/source/types/types.go +++ b/source/types/types.go @@ -15,19 +15,14 @@ package types import ( - "time" - "github.com/jackc/pgx/v5/pgtype" ) var ( Numeric = NumericFormatter{} - Time = TimeFormatter{} UUID = UUIDFormatter{} ) -var WithBuiltinPlugin = true - func Format(oid uint32, v any) (any, error) { if oid == pgtype.UUIDOID { return UUID.Format(v) @@ -38,10 +33,6 @@ func Format(oid uint32, v any) (any, error) { return Numeric.Format(t) case *pgtype.Numeric: return Numeric.Format(*t) - case time.Time: - return Time.Format(t) - case *time.Time: - return Time.Format(*t) case []uint8: if oid == pgtype.XMLOID { return string(t), nil diff --git a/source/types/types_test.go b/source/types/types_test.go index 7a13395..3c42d2f 100644 --- a/source/types/types_test.go +++ b/source/types/types_test.go @@ -56,25 +56,6 @@ func Test_Format(t *testing.T) { float64(12.2121), int64(101), nil, nil, }, }, - { - name: "time.Time", - input: []any{ - func() time.Time { - is := is.New(t) - is.Helper() - t, err := time.Parse(time.DateTime, "2009-11-10 23:00:00") - is.NoErr(err) - return t - }(), - nil, - }, - inputOID: []uint32{ - 0, 0, - }, - expect: []any{ - "2009-11-10 23:00:00 +0000 UTC", nil, - }, - }, { name: "builtin time.Time", input: []any{ @@ -107,13 +88,6 @@ func Test_Format(t *testing.T) { t.Run(tc.name, func(t *testing.T) { is := is.New(t) - prevWithBuiltinPlugin := WithBuiltinPlugin - WithBuiltinPlugin = tc.withBuiltin - - t.Cleanup(func() { - WithBuiltinPlugin = prevWithBuiltinPlugin - }) - for i, in := range tc.input { v, err := Format(tc.inputOID[i], in) is.NoErr(err)