Update golangci-lint and turn it on in CI

This commit is contained in:
Dmitry Kropachev
2024-06-14 13:07:21 -04:00
committed by Sylwia Szunejko
parent a9ab270196
commit ab80d70106
37 changed files with 225 additions and 151 deletions

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
//go:build all || integration
// +build all integration
package cql
@@ -9,5 +10,6 @@ package cql
import "embed"
// Files contains *.cql schema migration files.
//
//go:embed *.cql
var Files embed.FS

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a ALv2-style
// license that can be found in the LICENSE file.
//go:build all || integration
// +build all integration
package example

View File

@@ -7,7 +7,6 @@ package migrate
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"io/fs"
@@ -20,6 +19,7 @@ import (
"time"
"github.com/gocql/gocql"
"github.com/scylladb/gocqlx/v2"
"github.com/scylladb/gocqlx/v2/qb"
)
@@ -58,11 +58,11 @@ const (
// Info contains information on migration applied on a database.
type Info struct {
StartTime time.Time
EndTime time.Time
Name string
Checksum string
Done int
StartTime time.Time
EndTime time.Time
}
// List provides a listing of applied migrations.
@@ -128,8 +128,7 @@ func FromFS(ctx context.Context, session gocqlx.Session, f fs.FS) error {
for i := 0; i < len(dbm); i++ {
if dbm[i].Name != fm[i] {
fmt.Println(dbm[i].Name, fm[i], i)
return errors.New("inconsistent migrations")
return fmt.Errorf("inconsistent migrations found, expected %q got %q at %d", fm[i], dbm[i].Name, i)
}
c, err := fileChecksum(f, fm[i])
if err != nil {

View File

@@ -15,8 +15,9 @@ import (
"testing"
"github.com/psanford/memfs"
"github.com/scylladb/gocqlx/v2"
. "github.com/scylladb/gocqlx/v2/gocqlxtest"
"github.com/scylladb/gocqlx/v2/gocqlxtest"
"github.com/scylladb/gocqlx/v2/migrate"
)
@@ -45,7 +46,7 @@ func recreateTables(tb testing.TB, session gocqlx.Session) {
}
func TestMigration(t *testing.T) {
session := CreateSession(t)
session := gocqlxtest.CreateSession(t)
defer session.Close()
recreateTables(t, session)
@@ -91,7 +92,7 @@ func TestMigration(t *testing.T) {
}
func TestMigrationNoSemicolon(t *testing.T) {
session := CreateSession(t)
session := gocqlxtest.CreateSession(t)
defer session.Close()
recreateTables(t, session)
@@ -171,11 +172,11 @@ func TestMigrationCallback(t *testing.T) {
migrate.Callback = func(ctx context.Context, session gocqlx.Session, ev migrate.CallbackEvent, name string) error {
switch ev {
case migrate.BeforeMigration:
beforeCalled += 1
beforeCalled++
case migrate.AfterMigration:
afterCalled += 1
afterCalled++
case migrate.CallComment:
inCalled += 1
inCalled++
}
return nil
}
@@ -191,6 +192,8 @@ func TestMigrationCallback(t *testing.T) {
}
assertCallbacks := func(t *testing.T, before, afer, in int) {
t.Helper()
if beforeCalled != before {
t.Fatalf("expected %d before calls got %d", before, beforeCalled)
}
@@ -202,7 +205,7 @@ func TestMigrationCallback(t *testing.T) {
}
}
session := CreateSession(t)
session := gocqlxtest.CreateSession(t)
defer session.Close()
recreateTables(t, session)