From ba8deba4bbcf0c934c5eb7f924c0680f6fea3364 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 5 Sep 2024 20:26:36 -0700 Subject: [PATCH 1/2] Upgrade Deps + Unbreak tests. --- go.mod | 2 +- go.sum | 4 ++-- lib/debezium/converters/decimal_test.go | 8 ++++++-- lib/debezium/converters/money_test.go | 8 ++++++-- lib/debezium/converters/time_test.go | 15 --------------- sources/postgres/adapter/adapter_test.go | 7 ++++--- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 1eb8edde..9c0d277a 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/DataDog/datadog-go/v5 v5.5.0 - github.com/artie-labs/transfer v1.26.29 + github.com/artie-labs/transfer v1.26.31 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.27 github.com/aws/aws-sdk-go-v2/credentials v1.17.27 diff --git a/go.sum b/go.sum index 024e130f..2d9e32e1 100644 --- a/go.sum +++ b/go.sum @@ -93,8 +93,8 @@ github.com/apache/thrift v0.0.0-20181112125854-24918abba929/go.mod h1:cp2SuWMxlE github.com/apache/thrift v0.14.2/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.17.0 h1:cMd2aj52n+8VoAtvSvLn4kDC3aZ6IAkBuqWQ2IDu7wo= github.com/apache/thrift v0.17.0/go.mod h1:OLxhMRJxomX+1I/KUw03qoV3mMz16BwaKI+d4fPBx7Q= -github.com/artie-labs/transfer v1.26.29 h1:oqyeGX1nAIbD1PEZ7/FUSUHLGycKnP456Mbpw4Wgjxs= -github.com/artie-labs/transfer v1.26.29/go.mod h1:+a/UhlQVRIpdz3muS1yhSvyX42RQL0LHOdovGZfEsDE= +github.com/artie-labs/transfer v1.26.31 h1:mnz50FnH8MLnEu83FdK5z/E5zZD42hR2Hz9i1Uqxz/A= +github.com/artie-labs/transfer v1.26.31/go.mod h1:+a/UhlQVRIpdz3muS1yhSvyX42RQL0LHOdovGZfEsDE= github.com/aws/aws-sdk-go v1.30.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go-v2 v1.16.12/go.mod h1:C+Ym0ag2LIghJbXhfXZ0YEEp49rBWowxKzJLUoob0ts= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= diff --git a/lib/debezium/converters/decimal_test.go b/lib/debezium/converters/decimal_test.go index b16d7a79..efaf2a2c 100644 --- a/lib/debezium/converters/decimal_test.go +++ b/lib/debezium/converters/decimal_test.go @@ -216,9 +216,13 @@ func TestDecimalConverter_Convert(t *testing.T) { assert.NoError(t, err) bytes, ok := converted.([]byte) assert.True(t, ok) - actualValue, err := converter.ToField("").DecodeDecimal(bytes) + + valConverter, err := converter.ToField("").ToValueConverter() + assert.NoError(t, err) + + actualValue, err := valConverter.Convert(bytes) assert.NoError(t, err) - assert.Equal(t, "1.23", fmt.Sprint(actualValue)) + assert.Equal(t, "1.23", actualValue.(*decimal.Decimal).String()) } } diff --git a/lib/debezium/converters/money_test.go b/lib/debezium/converters/money_test.go index 6e6d6e6c..d9010f74 100644 --- a/lib/debezium/converters/money_test.go +++ b/lib/debezium/converters/money_test.go @@ -1,6 +1,7 @@ package converters import ( + "github.com/artie-labs/transfer/lib/typing/decimal" "testing" "github.com/artie-labs/reader/lib/ptr" @@ -41,9 +42,12 @@ func TestMoneyConverter_Convert(t *testing.T) { decodeValue := func(value any) string { bytes, ok := value.([]byte) assert.True(t, ok) - val, err := decimalField.DecodeDecimal(bytes) + + valueConverter, err := decimalField.ToValueConverter() + assert.NoError(t, err) + val, err := valueConverter.Convert(bytes) assert.NoError(t, err) - return val.String() + return val.(*decimal.Decimal).String() } { // Converter where mutateString is true diff --git a/lib/debezium/converters/time_test.go b/lib/debezium/converters/time_test.go index 6380d1a8..237ddc7d 100644 --- a/lib/debezium/converters/time_test.go +++ b/lib/debezium/converters/time_test.go @@ -1,7 +1,6 @@ package converters import ( - "fmt" "math" "testing" "time" @@ -12,20 +11,6 @@ import ( ) func parseUsingTransfer(converter ValueConverter, value int64) (*ext.ExtendedTime, error) { - if transferConverter := converter.ToField("foo").ToValueConverter(); transferConverter != nil { - val, err := transferConverter.Convert(value) - if err != nil { - return nil, err - } - - extTime, isOk := val.(*ext.ExtendedTime) - if !isOk { - return nil, fmt.Errorf("expected *ext.ExtendedTime got %T", val) - } - - return extTime, nil - } - parsedValue, err := converter.ToField("foo").ParseValue(value) if err != nil { return nil, err diff --git a/sources/postgres/adapter/adapter_test.go b/sources/postgres/adapter/adapter_test.go index 80e5071c..00c3506a 100644 --- a/sources/postgres/adapter/adapter_test.go +++ b/sources/postgres/adapter/adapter_test.go @@ -1,6 +1,7 @@ package adapter import ( + "github.com/artie-labs/transfer/lib/typing/decimal" "testing" "time" @@ -262,10 +263,10 @@ func TestValueConverterForType_Convert(t *testing.T) { if tc.numericValue { bytes, ok := actualValue.([]byte) assert.True(t, ok) - field := converter.ToField(tc.col.Name) - val, err := field.DecodeDecimal(bytes) + + val, err := converter.ToField(tc.col.Name).ParseValue(bytes) assert.NoError(t, err, tc.name) - assert.Equal(t, tc.expectedValue, val.String(), tc.name) + assert.Equal(t, tc.expectedValue, val.(*decimal.Decimal).String(), tc.name) } else { assert.Equal(t, tc.expectedValue, actualValue, tc.name) } From 7f459674db7a011d9e251b580a7c1730b8174c16 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 5 Sep 2024 20:27:46 -0700 Subject: [PATCH 2/2] Clean up tests + imports. --- lib/debezium/converters/decimal_test.go | 5 +---- lib/debezium/converters/money_test.go | 2 +- sources/postgres/adapter/adapter_test.go | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/debezium/converters/decimal_test.go b/lib/debezium/converters/decimal_test.go index efaf2a2c..adc09f8c 100644 --- a/lib/debezium/converters/decimal_test.go +++ b/lib/debezium/converters/decimal_test.go @@ -217,10 +217,7 @@ func TestDecimalConverter_Convert(t *testing.T) { bytes, ok := converted.([]byte) assert.True(t, ok) - valConverter, err := converter.ToField("").ToValueConverter() - assert.NoError(t, err) - - actualValue, err := valConverter.Convert(bytes) + actualValue, err := converter.ToField("").ParseValue(bytes) assert.NoError(t, err) assert.Equal(t, "1.23", actualValue.(*decimal.Decimal).String()) } diff --git a/lib/debezium/converters/money_test.go b/lib/debezium/converters/money_test.go index d9010f74..6c412525 100644 --- a/lib/debezium/converters/money_test.go +++ b/lib/debezium/converters/money_test.go @@ -1,11 +1,11 @@ package converters import ( - "github.com/artie-labs/transfer/lib/typing/decimal" "testing" "github.com/artie-labs/reader/lib/ptr" transferDbz "github.com/artie-labs/transfer/lib/debezium" + "github.com/artie-labs/transfer/lib/typing/decimal" "github.com/stretchr/testify/assert" ) diff --git a/sources/postgres/adapter/adapter_test.go b/sources/postgres/adapter/adapter_test.go index 00c3506a..6e924e90 100644 --- a/sources/postgres/adapter/adapter_test.go +++ b/sources/postgres/adapter/adapter_test.go @@ -1,7 +1,6 @@ package adapter import ( - "github.com/artie-labs/transfer/lib/typing/decimal" "testing" "time" @@ -10,6 +9,7 @@ import ( "github.com/artie-labs/reader/lib/postgres" "github.com/artie-labs/reader/lib/postgres/schema" "github.com/artie-labs/transfer/lib/debezium" + "github.com/artie-labs/transfer/lib/typing/decimal" ) func TestPostgresAdapter_TableName(t *testing.T) {