From cc8fb1e9291bb0e60c13313d23577f774c193b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Tue, 24 Dec 2024 20:58:33 +0000 Subject: [PATCH] golangci-lint 1.62 Enable new linters: iface & recvcheck --- .github/workflows/golang-lint.yml | 2 +- flow/.golangci.yml | 7 +++++++ flow/connectors/core.go | 2 ++ flow/connectors/postgres/qrep_query_executor_test.go | 3 +-- flow/connectors/sql/query_executor.go | 1 + flow/connectors/utils/aws.go | 4 ++-- flow/e2e/bigquery/peer_flow_bq_test.go | 2 +- flow/e2e/sqlserver/sqlserver_helper.go | 3 +-- flow/shared/telemetry/incidentio_message_sender.go | 10 +++------- .../telemetry/incidentio_message_sender_test.go | 4 ++-- flow/shared/telemetry/{interface.go => sender.go} | 5 +++++ flow/shared/telemetry/sns_message_sender.go | 12 ++++-------- 12 files changed, 30 insertions(+), 25 deletions(-) rename flow/shared/telemetry/{interface.go => sender.go} (91%) diff --git a/.github/workflows/golang-lint.yml b/.github/workflows/golang-lint.yml index 2a176a077e..9b4e558a75 100644 --- a/.github/workflows/golang-lint.yml +++ b/.github/workflows/golang-lint.yml @@ -29,6 +29,6 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6 with: - version: v1.61 + version: v1.62 working-directory: ./flow args: --timeout=10m diff --git a/flow/.golangci.yml b/flow/.golangci.yml index 745c15ee50..23d8a169a9 100644 --- a/flow/.golangci.yml +++ b/flow/.golangci.yml @@ -15,6 +15,7 @@ linters: - gofumpt - gosec - gosimple + - iface - ineffassign - intrange - lll @@ -25,6 +26,7 @@ linters: - nonamedreturns - perfsprint - prealloc + - recvcheck - rowserrcheck - staticcheck - stylecheck @@ -66,6 +68,11 @@ linters-settings: enable-all: true disable: - shadow + iface: + enable: + - identical + - unused + - opaque stylecheck: checks: - all diff --git a/flow/connectors/core.go b/flow/connectors/core.go index 47dc0ece06..8a52b01c31 100644 --- a/flow/connectors/core.go +++ b/flow/connectors/core.go @@ -463,6 +463,8 @@ var ( _ CDCSyncConnector = &connclickhouse.ClickHouseConnector{} _ CDCSyncConnector = &connelasticsearch.ElasticsearchConnector{} + _ CDCSyncPgConnector = &connpostgres.PostgresConnector{} + _ CDCNormalizeConnector = &connpostgres.PostgresConnector{} _ CDCNormalizeConnector = &connbigquery.BigQueryConnector{} _ CDCNormalizeConnector = &connsnowflake.SnowflakeConnector{} diff --git a/flow/connectors/postgres/qrep_query_executor_test.go b/flow/connectors/postgres/qrep_query_executor_test.go index eaa015c1cf..78f82b07ea 100644 --- a/flow/connectors/postgres/qrep_query_executor_test.go +++ b/flow/connectors/postgres/qrep_query_executor_test.go @@ -186,8 +186,7 @@ func TestAllDataTypes(t *testing.T) { expectedBytea := []byte("bytea") require.Equal(t, expectedBytea, record[6].Value(), "expected 'bytea'") - expectedJSON := `{"key":"value"}` - require.Equal(t, expectedJSON, record[7].Value(), "expected '{\"key\":\"value\"}'") + require.JSONEq(t, `{"key":"value"}`, record[7].Value().(string), "expected '{\"key\":\"value\"}'") actualUUID := record[8].Value().(uuid.UUID) require.Equal(t, savedUUID[:], actualUUID[:], "expected savedUUID: %v", savedUUID) diff --git a/flow/connectors/sql/query_executor.go b/flow/connectors/sql/query_executor.go index 4be60f4a51..b110aa76ed 100644 --- a/flow/connectors/sql/query_executor.go +++ b/flow/connectors/sql/query_executor.go @@ -19,6 +19,7 @@ import ( "github.com/PeerDB-io/peer-flow/model/qvalue" ) +//nolint:iface type SQLQueryExecutor interface { ConnectionActive(context.Context) error Close() error diff --git a/flow/connectors/utils/aws.go b/flow/connectors/utils/aws.go index 73eab604ad..a9b212517b 100644 --- a/flow/connectors/utils/aws.go +++ b/flow/connectors/utils/aws.go @@ -103,7 +103,7 @@ func (r *ConfigBasedAWSCredentialsProvider) Retrieve(ctx context.Context) (AWSCr }, nil } -func NewConfigBasedAWSCredentialsProvider(config aws.Config) AWSCredentialsProvider { +func NewConfigBasedAWSCredentialsProvider(config aws.Config) *ConfigBasedAWSCredentialsProvider { return &ConfigBasedAWSCredentialsProvider{config: config} } @@ -132,7 +132,7 @@ func (s *StaticAWSCredentialsProvider) GetEndpointURL() string { return "" } -func NewStaticAWSCredentialsProvider(credentials AWSCredentials, region string) AWSCredentialsProvider { +func NewStaticAWSCredentialsProvider(credentials AWSCredentials, region string) *StaticAWSCredentialsProvider { return &StaticAWSCredentialsProvider{ credentials: credentials, region: region, diff --git a/flow/e2e/bigquery/peer_flow_bq_test.go b/flow/e2e/bigquery/peer_flow_bq_test.go index 674a21ebf5..8fcb263694 100644 --- a/flow/e2e/bigquery/peer_flow_bq_test.go +++ b/flow/e2e/bigquery/peer_flow_bq_test.go @@ -55,7 +55,7 @@ func (s PeerFlowE2ETestSuiteBQ) attachSuffix(input string) string { return fmt.Sprintf("%s_%s", input, s.bqSuffix) } -func (s *PeerFlowE2ETestSuiteBQ) checkPeerdbColumns(dstQualified string, softDelete bool) error { +func (s PeerFlowE2ETestSuiteBQ) checkPeerdbColumns(dstQualified string, softDelete bool) error { qualifiedTableName := fmt.Sprintf("`%s.%s`", s.bqHelper.Config.DatasetId, dstQualified) selector := "`_PEERDB_SYNCED_AT`" if softDelete { diff --git a/flow/e2e/sqlserver/sqlserver_helper.go b/flow/e2e/sqlserver/sqlserver_helper.go index d3e1401f24..154ffbea5e 100644 --- a/flow/e2e/sqlserver/sqlserver_helper.go +++ b/flow/e2e/sqlserver/sqlserver_helper.go @@ -7,7 +7,6 @@ import ( "os" "strconv" - peersql "github.com/PeerDB-io/peer-flow/connectors/sql" connsqlserver "github.com/PeerDB-io/peer-flow/connectors/sqlserver" "github.com/PeerDB-io/peer-flow/generated/protos" "github.com/PeerDB-io/peer-flow/model/qvalue" @@ -16,7 +15,7 @@ import ( type SQLServerHelper struct { config *protos.SqlServerConfig - E peersql.SQLQueryExecutor + E *connsqlserver.SQLServerConnector SchemaName string tables []string } diff --git a/flow/shared/telemetry/incidentio_message_sender.go b/flow/shared/telemetry/incidentio_message_sender.go index 53e05628fa..ead24dd9a6 100644 --- a/flow/shared/telemetry/incidentio_message_sender.go +++ b/flow/shared/telemetry/incidentio_message_sender.go @@ -30,10 +30,6 @@ type IncidentIoResponse struct { } type IncidentIoMessageSender struct { - Sender -} - -type IncidentIoMessageSenderImpl struct { http *http.Client config IncidentIoMessageSenderConfig } @@ -43,7 +39,7 @@ type IncidentIoMessageSenderConfig struct { Token string } -func (i *IncidentIoMessageSenderImpl) SendMessage( +func (i *IncidentIoMessageSender) SendMessage( ctx context.Context, subject string, body string, @@ -117,12 +113,12 @@ func (i *IncidentIoMessageSenderImpl) SendMessage( return incidentResponse.Status, nil } -func NewIncidentIoMessageSender(_ context.Context, config IncidentIoMessageSenderConfig) (Sender, error) { +func NewIncidentIoMessageSender(_ context.Context, config IncidentIoMessageSenderConfig) (*IncidentIoMessageSender, error) { client := &http.Client{ Timeout: time.Second * 5, } - return &IncidentIoMessageSenderImpl{ + return &IncidentIoMessageSender{ config: config, http: client, }, nil diff --git a/flow/shared/telemetry/incidentio_message_sender_test.go b/flow/shared/telemetry/incidentio_message_sender_test.go index ce629abcde..c872935a8c 100644 --- a/flow/shared/telemetry/incidentio_message_sender_test.go +++ b/flow/shared/telemetry/incidentio_message_sender_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestIncidentIoMessageSenderImpl_SendMessage(t *testing.T) { +func TestIncidentIoMessageSender_SendMessage(t *testing.T) { tests := []struct { serverResponse IncidentIoResponse name string @@ -168,7 +168,7 @@ func TestIncidentIoMessageSenderImpl_SendMessage(t *testing.T) { URL: fakeIncidentIoServer.URL, Token: "test-token", } - sender := &IncidentIoMessageSenderImpl{ + sender := &IncidentIoMessageSender{ http: &http.Client{Timeout: time.Second * 5}, config: config, } diff --git a/flow/shared/telemetry/interface.go b/flow/shared/telemetry/sender.go similarity index 91% rename from flow/shared/telemetry/interface.go rename to flow/shared/telemetry/sender.go index 1c2ed159a4..33a7c61e3e 100644 --- a/flow/shared/telemetry/interface.go +++ b/flow/shared/telemetry/sender.go @@ -8,6 +8,11 @@ type Sender interface { SendMessage(ctx context.Context, subject string, body string, attributes Attributes) (string, error) } +var ( + _ Sender = &IncidentIoMessageSender{} + _ Sender = &SNSMessageSender{} +) + type Attributes struct { DeploymentUID string Type string diff --git a/flow/shared/telemetry/sns_message_sender.go b/flow/shared/telemetry/sns_message_sender.go index 193f47c525..2a4798e3ed 100644 --- a/flow/shared/telemetry/sns_message_sender.go +++ b/flow/shared/telemetry/sns_message_sender.go @@ -15,11 +15,7 @@ import ( "github.com/PeerDB-io/peer-flow/shared/aws_common" ) -type SNSMessageSender interface { - Sender -} - -type SNSMessageSenderImpl struct { +type SNSMessageSender struct { client *sns.Client topic string } @@ -28,7 +24,7 @@ type SNSMessageSenderConfig struct { Topic string `json:"topic"` } -func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string, body string, attributes Attributes) (string, error) { +func (s *SNSMessageSender) SendMessage(ctx context.Context, subject string, body string, attributes Attributes) (string, error) { activityInfo := activity.Info{} if activity.IsActivity(ctx) { activityInfo = activity.GetInfo(ctx) @@ -92,14 +88,14 @@ func (s *SNSMessageSenderImpl) SendMessage(ctx context.Context, subject string, return *publish.MessageId, nil } -func NewSNSMessageSenderWithNewClient(ctx context.Context, config *SNSMessageSenderConfig) (SNSMessageSender, error) { +func NewSNSMessageSenderWithNewClient(ctx context.Context, config *SNSMessageSenderConfig) (*SNSMessageSender, error) { // Topic Region must match client region region := strings.Split(strings.TrimPrefix(config.Topic, "arn:aws:sns:"), ":")[0] client, err := newSnsClient(ctx, ®ion) if err != nil { return nil, err } - return &SNSMessageSenderImpl{ + return &SNSMessageSender{ client: client, topic: config.Topic, }, nil