From fa3c28d7fa685305f5736d95cddf959633f7f0ac Mon Sep 17 00:00:00 2001 From: maha-hajja Date: Thu, 20 Apr 2023 23:25:27 +0100 Subject: [PATCH 1/2] go 1.20 --- .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 2 +- README.md | 2 +- go.mod | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c38fec..677abe3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: '1.20' - name: Test env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b292c3a..0a456fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: '1.18' + go-version: '1.20' - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3.4.0 diff --git a/README.md b/README.md index b2625f6..e59a51d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It provides both, a source and a destination SQL SERVER connector. ### Prerequisites -- [Go](https://go.dev/) 1.18 +- [Go](https://go.dev/) '1.20' - (optional) [golangci-lint](https://github.com/golangci/golangci-lint) 1.48.0 - (optional) [mock](https://github.com/golang/mock) 1.6.0 diff --git a/go.mod b/go.mod index 50f61a3..7e812c2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/conduitio-labs/conduit-connector-sql-server -go 1.18 +go 1.20 require ( github.com/conduitio/conduit-connector-sdk v0.6.0 From 352699e446f59d4a56b8f49830e1a6f0dbe42520 Mon Sep 17 00:00:00 2001 From: maha-hajja Date: Thu, 20 Apr 2023 23:39:16 +0100 Subject: [PATCH 2/2] upgrade golangci-lint --- .github/workflows/lint.yml | 2 +- columntypes/columntypes.go | 9 +++++++-- columntypes/columntypes_test.go | 9 +++++---- destination/destination.go | 2 +- destination/destination_integration_test.go | 16 ++++++++++++++++ destination/writer/writer.go | 2 +- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0a456fb..67a8ac0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,4 +16,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3.4.0 with: - version: v1.50.1 + version: v1.52.2 diff --git a/columntypes/columntypes.go b/columntypes/columntypes.go index 469b725..ebdea8b 100644 --- a/columntypes/columntypes.go +++ b/columntypes/columntypes.go @@ -70,7 +70,7 @@ type Querier interface { } // TransformRow converts row map values to appropriate Go types, based on the columnTypes. -func TransformRow(ctx context.Context, row map[string]any, columnTypes map[string]string) (map[string]any, error) { +func TransformRow(_ context.Context, row map[string]any, columnTypes map[string]string) (map[string]any, error) { result := make(map[string]any, len(row)) for key, value := range row { @@ -100,7 +100,7 @@ func TransformRow(ctx context.Context, row map[string]any, columnTypes map[strin // ConvertStructureData converts a sdk.StructureData values to a proper database types. func ConvertStructureData( - ctx context.Context, + _ context.Context, columnTypes map[string]string, data sdk.StructuredData, ) (sdk.StructuredData, error) { @@ -177,6 +177,7 @@ func GetColumnTypes(ctx context.Context, querier Querier, tableName string) (map if err != nil { return nil, fmt.Errorf("query column types: %w", err) } + defer rows.Close() columnTypes := make(map[string]string) for rows.Next() { @@ -188,6 +189,10 @@ func GetColumnTypes(ctx context.Context, querier Querier, tableName string) (map columnTypes[columnName] = dataType } + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("iterate rows error: %w", err) + } + return columnTypes, nil } diff --git a/columntypes/columntypes_test.go b/columntypes/columntypes_test.go index dd2b9ce..faeb5ec 100644 --- a/columntypes/columntypes_test.go +++ b/columntypes/columntypes_test.go @@ -44,12 +44,13 @@ func Test_parseToTime(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + tc := tt // create a new variable inside the loop and assign the loop variable to it + t.Run(tc.name, func(t *testing.T) { t.Parallel() - _, err := parseToTime(tt.strValue) - if (err != nil) != tt.wantErr { - t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr) + _, err := parseToTime(tc.strValue) + if (err != nil) != tc.wantErr { + t.Errorf("Parse() error = %v, wantErr %v", err, tc.wantErr) return } diff --git a/destination/destination.go b/destination/destination.go index 61e8193..9f7d2b9 100644 --- a/destination/destination.go +++ b/destination/destination.go @@ -57,7 +57,7 @@ func (d *Destination) Parameters() map[string]sdk.Parameter { } // Configure parses and initializes the config. -func (d *Destination) Configure(ctx context.Context, cfg map[string]string) error { +func (d *Destination) Configure(_ context.Context, cfg map[string]string) error { configuration, err := config.Parse(cfg) if err != nil { return fmt.Errorf("parse config: %w", err) diff --git a/destination/destination_integration_test.go b/destination/destination_integration_test.go index d58e2d8..563495b 100644 --- a/destination/destination_integration_test.go +++ b/destination/destination_integration_test.go @@ -140,6 +140,10 @@ func TestIntegrationDestination_Write_Insert_Success(t *testing.T) { } } + if err := rows.Err(); err != nil { + t.Error("iterate rows error: %w", err) + } + if id != preparedID { t.Error(errors.New("id and prepared id not equal")) } @@ -252,6 +256,10 @@ func TestIntegrationDestination_Write_Update_Success(t *testing.T) { } } + if err := rows.Err(); err != nil { + t.Error("iterate rows error: %w", err) + } + if clVarchar != preparedVarchar { t.Error(errors.New("clVarchar and preparedVarchar not equal")) } @@ -364,6 +372,10 @@ func TestIntegrationDestination_Write_Update_Composite_Keys_Success(t *testing.T } } + if err := rows.Err(); err != nil { + t.Error("iterate rows error: %w", err) + } + if clVarchar != preparedVarchar { t.Error(errors.New("clVarchar and preparedVarchar not equal")) } @@ -479,6 +491,10 @@ func TestIntegrationDestination_Write_Delete_Success(t *testing.T) { } } + if err := rows.Err(); err != nil { + t.Error("iterate rows error: %w", err) + } + if count != 0 { t.Error(errors.New("count not zero")) } diff --git a/destination/writer/writer.go b/destination/writer/writer.go index 7691cba..264cfa0 100644 --- a/destination/writer/writer.go +++ b/destination/writer/writer.go @@ -66,7 +66,7 @@ func NewWriter(ctx context.Context, params Params) (*Writer, error) { } // Close closes the underlying db connection. -func (w *Writer) Close(ctx context.Context) error { +func (w *Writer) Close(_ context.Context) error { return w.db.Close() }