Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (m *mockDriver) Drop() error {
func TestRegisterTwice(t *testing.T) {
Register("mock", &mockDriver{})

var err interface{}
var err any
func() {
defer func() {
err = recover()
Expand Down
10 changes: 4 additions & 6 deletions database/neo4j/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ var (
DefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB
)

var (
ErrNilConfig = fmt.Errorf("no config")
)
var ErrNilConfig = fmt.Errorf("no config")

type Config struct {
MigrationsLabel string
Expand Down Expand Up @@ -146,7 +144,7 @@ func (n *Neo4j) Run(migration io.Reader) (err error) {
}()

if n.config.MultiStatement {
_, err = session.WriteTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
_, err = session.WriteTransaction(func(transaction neo4j.Transaction) (any, error) {
var stmtRunErr error
if err := multistmt.Parse(migration, StatementSeparator, n.config.MultiStatementMaxSize, func(stmt []byte) bool {
trimStmt := bytes.TrimSpace(stmt)
Expand Down Expand Up @@ -194,7 +192,7 @@ func (n *Neo4j) SetVersion(version int, dirty bool) (err error) {

query := fmt.Sprintf("MERGE (sm:%s {version: $version}) SET sm.dirty = $dirty, sm.ts = datetime()",
n.config.MigrationsLabel)
_, err = neo4j.Collect(session.Run(query, map[string]interface{}{"version": version, "dirty": dirty}))
_, err = neo4j.Collect(session.Run(query, map[string]any{"version": version, "dirty": dirty}))
if err != nil {
return err
}
Expand All @@ -220,7 +218,7 @@ func (n *Neo4j) Version() (version int, dirty bool, err error) {
query := fmt.Sprintf(`MATCH (sm:%s) RETURN sm.version AS version, sm.dirty AS dirty
ORDER BY COALESCE(sm.ts, datetime({year: 0})) DESC, sm.version DESC LIMIT 1`,
n.config.MigrationsLabel)
result, err := session.ReadTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
result, err := session.ReadTransaction(func(transaction neo4j.Transaction) (any, error) {
result, err := transaction.Run(query, nil)
if err != nil {
return nil, err
Expand Down
12 changes: 4 additions & 8 deletions database/pgx/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
var (
opts = dktest.Options{
Env: map[string]string{"POSTGRES_PASSWORD": pgPassword},
PortRequired: true, ReadyFunc: isReady}
PortRequired: true, ReadyFunc: isReady,
}
// Supported versions: https://www.postgresql.org/support/versioning/
specs = []dktesting.ContainerSpec{
{ImageName: "postgres:13", Options: opts},
Expand Down Expand Up @@ -406,7 +407,6 @@ func TestMigrationTableOption(t *testing.T) {
if !exists {
t.Fatalf("expected table 'migrate.schema_migrations' to exist")
}

})
}

Expand All @@ -423,7 +423,6 @@ func TestFailToCreateTableWithoutPermissions(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -493,7 +492,6 @@ func TestCheckBeforeCreateTable(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand All @@ -516,7 +514,6 @@ func TestCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d2, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}
Expand All @@ -534,13 +531,11 @@ func TestCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d3, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}

version, _, err := d3.Version()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -694,7 +689,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand All @@ -705,6 +700,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
}
})
}

func Test_computeLineFromPos(t *testing.T) {
testcases := []struct {
pos int
Expand Down
12 changes: 4 additions & 8 deletions database/pgx/v5/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
var (
opts = dktest.Options{
Env: map[string]string{"POSTGRES_PASSWORD": pgPassword},
PortRequired: true, ReadyFunc: isReady}
PortRequired: true, ReadyFunc: isReady,
}
// Supported versions: https://www.postgresql.org/support/versioning/
specs = []dktesting.ContainerSpec{
{ImageName: "postgres:13", Options: opts},
Expand Down Expand Up @@ -381,7 +382,6 @@ func TestMigrationTableOption(t *testing.T) {
if !exists {
t.Fatalf("expected table 'migrate.schema_migrations' to exist")
}

})
}

Expand All @@ -398,7 +398,6 @@ func TestFailToCreateTableWithoutPermissions(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -468,7 +467,6 @@ func TestCheckBeforeCreateTable(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand All @@ -491,7 +489,6 @@ func TestCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d2, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}
Expand All @@ -509,13 +506,11 @@ func TestCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d3, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}

version, _, err := d3.Version()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -669,7 +664,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand All @@ -680,6 +675,7 @@ func TestWithInstance_Concurrent(t *testing.T) {
}
})
}

func Test_computeLineFromPos(t *testing.T) {
testcases := []struct {
pos int
Expand Down
11 changes: 3 additions & 8 deletions database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
var (
opts = dktest.Options{
Env: map[string]string{"POSTGRES_PASSWORD": pgPassword},
PortRequired: true, ReadyFunc: isReady}
PortRequired: true, ReadyFunc: isReady,
}
// Supported versions: https://www.postgresql.org/support/versioning/
specs = []dktesting.ContainerSpec{
{ImageName: "postgres:13", Options: opts},
Expand Down Expand Up @@ -409,7 +410,6 @@ func testMigrationTableOption(t *testing.T) {
if !exists {
t.Fatalf("expected table 'migrate.schema_migrations' to exist")
}

})
}

Expand All @@ -426,7 +426,6 @@ func testFailToCreateTableWithoutPermissions(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -496,7 +495,6 @@ func testCheckBeforeCreateTable(t *testing.T) {
p := &Postgres{}

d, err := p.Open(addr)

if err != nil {
t.Fatal(err)
}
Expand All @@ -519,7 +517,6 @@ func testCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d2, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}
Expand All @@ -537,13 +534,11 @@ func testCheckBeforeCreateTable(t *testing.T) {
// re-connect using that schema
d3, err := p.Open(fmt.Sprintf("postgres://not_owner:%s@%v:%v/postgres?sslmode=disable&search_path=barfoo",
pgPassword, ip, port))

if err != nil {
t.Fatal(err)
}

version, _, err := d3.Version()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -699,7 +694,7 @@ func testWithInstanceConcurrent(t *testing.T) {
defer wg.Wait()

wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
for i := range concurrency {
go func(i int) {
defer wg.Done()
_, err := WithInstance(db, &Config{})
Expand Down
2 changes: 1 addition & 1 deletion database/rqlite/rqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (r *Rqlite) SetVersion(version int, dirty bool) error {
if version >= 0 || (version == database.NilVersion && dirty) {
statements = append(statements, gorqlite.ParameterizedStatement{
Query: insertQuery,
Arguments: []interface{}{
Arguments: []any{
version,
dirty,
},
Expand Down
10 changes: 5 additions & 5 deletions database/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func (s *Spanner) Run(migration io.Reader) error {
Database: s.config.DatabaseName,
Statements: stmts,
})

if err != nil {
return &database.Error{OrigErr: err, Err: "migration failed", Query: migr}
}
Expand All @@ -200,10 +199,12 @@ func (s *Spanner) SetVersion(version int, dirty bool) error {
func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
m := []*spanner.Mutation{
spanner.Delete(s.config.MigrationsTable, spanner.AllKeys()),
spanner.Insert(s.config.MigrationsTable,
spanner.Insert(
s.config.MigrationsTable,
[]string{"Version", "Dirty"},
[]interface{}{version, dirty},
)}
[]any{version, dirty},
),
}
return txn.BufferWrite(m)
})
if err != nil {
Expand Down Expand Up @@ -318,7 +319,6 @@ func (s *Spanner) ensureVersionTable() (err error) {
Database: s.config.DatabaseName,
Statements: []string{stmt},
})

if err != nil {
return &database.Error{OrigErr: err, Query: []byte(stmt)}
}
Expand Down
4 changes: 2 additions & 2 deletions database/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {

type Stub struct {
Url string
Instance interface{}
Instance any
CurrentVersion int
MigrationSequence []string
LastRunMigration []byte // todo: make []string
Expand All @@ -35,7 +35,7 @@ func (s *Stub) Open(url string) (database.Driver, error) {

type Config struct{}

func WithInstance(instance interface{}, config *Config) (database.Driver, error) {
func WithInstance(instance any, config *Config) (database.Driver, error) {
return &Stub{
Instance: instance,
CurrentVersion: database.NilVersion,
Expand Down
6 changes: 2 additions & 4 deletions dktesting/dktesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ func (s *ContainerSpec) Cleanup() (retErr error) {

// ParallelTest runs Docker tests in parallel
func ParallelTest(t *testing.T, specs []ContainerSpec,
testFunc func(*testing.T, dktest.ContainerInfo)) {

testFunc func(*testing.T, dktest.ContainerInfo),
) {
for i, spec := range specs {
spec := spec // capture range variable, see https://goo.gl/60w3p2

// Only test against one version in short mode
// TODO: order is random, maybe always pick first version instead?
if i > 0 && testing.Short() {
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Log struct {
}

// Printf prints out formatted string into a log
func (l *Log) Printf(format string, v ...interface{}) {
func (l *Log) Printf(format string, v ...any) {
if l.verbose {
logpkg.Printf(format, v...)
} else {
Expand All @@ -21,7 +21,7 @@ func (l *Log) Printf(format string, v ...interface{}) {
}

// Println prints out args into a log
func (l *Log) Println(args ...interface{}) {
func (l *Log) Println(args ...any) {
if l.verbose {
logpkg.Println(args...)
} else {
Expand All @@ -34,7 +34,7 @@ func (l *Log) Verbose() bool {
return l.verbose
}

func (l *Log) fatal(args ...interface{}) {
func (l *Log) fatal(args ...any) {
l.Println(args...)
os.Exit(1)
}
Expand Down
Loading
Loading