aboutsummaryrefslogtreecommitdiffstats
path: root/internal/repositories/migration_db_repo_test.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-01-28 16:10:14 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-01-28 16:10:14 -0500
commitb06eba3df09a8fcd777b8fe350c2b184758963d1 (patch)
tree0a2ad3aa9537c0457688b7325a3858c1b328bea2 /internal/repositories/migration_db_repo_test.go
parentAdd version cmd to docs (diff)
downloadcli-b06eba3df09a8fcd777b8fe350c2b184758963d1.zip
Use checkmate for tests
Diffstat (limited to 'internal/repositories/migration_db_repo_test.go')
-rw-r--r--internal/repositories/migration_db_repo_test.go118
1 files changed, 59 insertions, 59 deletions
diff --git a/internal/repositories/migration_db_repo_test.go b/internal/repositories/migration_db_repo_test.go
index dc635b0..5d1a9f1 100644
--- a/internal/repositories/migration_db_repo_test.go
+++ b/internal/repositories/migration_db_repo_test.go
@@ -8,7 +8,7 @@ import (
"github.com/eugenetriguba/bolt/internal/bolttest"
"github.com/eugenetriguba/bolt/internal/models"
"github.com/eugenetriguba/bolt/internal/repositories"
- "gotest.tools/v3/assert"
+ "github.com/eugenetriguba/checkmate"
)
func TestMigrationDBRepo_NewMigrationDBRepoCreatesTable(t *testing.T) {
@@ -21,10 +21,10 @@ func TestMigrationDBRepo_NewMigrationDBRepoCreatesTable(t *testing.T) {
`)
var scanResult int
err := row.Scan(&scanResult)
- assert.ErrorIs(t, err, sql.ErrNoRows)
+ checkmate.AssertErrorIs(t, err, sql.ErrNoRows)
_, err = repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
row = db.QueryRow(`
SELECT 1
@@ -33,49 +33,49 @@ func TestMigrationDBRepo_NewMigrationDBRepoCreatesTable(t *testing.T) {
AND TABLE_NAME = 'bolt_migrations'
`)
err = row.Scan(&scanResult)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
}
func TestMigrationDBRepo_NewMigrationDBRepoLeavesCurrentTable(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
_, err := db.Exec(`CREATE TABLE bolt_migrations(id INT NOT NULL PRIMARY KEY)`)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
_, err = db.Exec(`INSERT INTO bolt_migrations(id) VALUES (1);`)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
_, err = repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
row := db.QueryRow(`SELECT id FROM bolt_migrations`)
var scanResult int
err = row.Scan(&scanResult)
- assert.NilError(t, err)
- assert.Equal(t, scanResult, 1)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, scanResult, 1)
}
func TestMigrationDBRepo_ListWithEmptyTable(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migrations, err := repo.List()
- assert.NilError(t, err)
- assert.Equal(t, len(migrations), 0)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, len(migrations), 0)
}
func TestMigrationDBRepo_ListWithSingleResult(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
version := "20230101000000"
_, err = db.Exec(`INSERT INTO bolt_migrations(version) VALUES ($1);`, version)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migrations, err := repo.List()
- assert.NilError(t, err)
- assert.Equal(t, len(migrations), 1)
- assert.DeepEqual(
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, len(migrations), 1)
+ checkmate.AssertDeepEqual(
t,
migrations[version],
&models.Migration{Version: version, Message: "", Applied: true},
@@ -85,16 +85,16 @@ func TestMigrationDBRepo_ListWithSingleResult(t *testing.T) {
func TestMigrationDBRepo_ListWithShortVersion(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
version := "20230101"
_, err = db.Exec(`INSERT INTO bolt_migrations(version) VALUES ($1);`, version)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migrations, err := repo.List()
- assert.NilError(t, err)
- assert.Equal(t, len(migrations), 1)
- assert.DeepEqual(
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, len(migrations), 1)
+ checkmate.AssertDeepEqual(
t,
migrations[version],
&models.Migration{Version: version, Message: "", Applied: true},
@@ -104,37 +104,37 @@ func TestMigrationDBRepo_ListWithShortVersion(t *testing.T) {
func TestMigrationDBRepo_IsAppliedWithNotApplied(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
version := "20230101010101"
applied, err := repo.IsApplied(version)
- assert.NilError(t, err)
- assert.Equal(t, applied, false)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, applied, false)
}
func TestMigrationDBRepo_IsAppliedWithApplied(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
version := "20230101010101"
_, err = db.Exec(`INSERT INTO bolt_migrations(version) VALUES ($1);`, version)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
applied, err := repo.IsApplied(version)
- assert.NilError(t, err)
- assert.Equal(t, applied, true)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, applied, true)
}
func TestMigrationDBRepo_Apply(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration := models.NewTimestampMigration(time.Now(), "test")
err = repo.Apply(`CREATE TABLE tmp(id INT NOT NULL PRIMARY KEY)`, migration)
- assert.NilError(t, err)
- assert.Equal(t, migration.Applied, true)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, migration.Applied, true)
row := db.QueryRow(`
SELECT 1
@@ -144,31 +144,31 @@ func TestMigrationDBRepo_Apply(t *testing.T) {
`)
var scanResult int
err = row.Scan(&scanResult)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
applied, err := repo.IsApplied(migration.Version)
- assert.NilError(t, err)
- assert.Equal(t, applied, true)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, applied, true)
}
func TestMigrationDBRepo_Revert(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
_, err = db.Exec(`CREATE TABLE tmp(id INT NOT NULL PRIMARY KEY)`)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration := models.NewTimestampMigration(time.Now(), "test")
_, err = db.Exec(
`INSERT INTO bolt_migrations(version) VALUES ($1);`,
migration.Version,
)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration.Applied = true
err = repo.Revert(`DROP TABLE tmp;`, migration)
- assert.NilError(t, err)
- assert.Equal(t, migration.Applied, false)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, migration.Applied, false)
row := db.QueryRow(`
SELECT 1
@@ -178,21 +178,21 @@ func TestMigrationDBRepo_Revert(t *testing.T) {
`)
var scanResult int
err = row.Scan(&scanResult)
- assert.ErrorIs(t, err, sql.ErrNoRows)
+ checkmate.AssertErrorIs(t, err, sql.ErrNoRows)
row = db.QueryRow(`SELECT count(*) FROM bolt_migrations`)
var count int
err = row.Scan(&count)
- assert.NilError(t, err)
- assert.Equal(t, count, 0)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, count, 0)
}
func TestMigrationDBRepo_ApplyAndRevertWithoutTransaction(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
_, err = db.Exec("CREATE TABLE tmp(id INT PRIMARY KEY, id2 INT, id3 INT)")
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration := models.NewTimestampMigration(time.Now(), "test")
// CREATE INDEX CONCURRENTLY cannot run inside a transaction.
@@ -200,44 +200,44 @@ func TestMigrationDBRepo_ApplyAndRevertWithoutTransaction(t *testing.T) {
`-- bolt: no-transaction\CREATE INDEX CONCURRENTLY i1 ON tmp(id2);`,
migration,
)
- assert.NilError(t, err)
- assert.Equal(t, migration.Applied, true)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, migration.Applied, true)
err = repo.Revert(
"-- bolt: no-transaction\nCREATE INDEX CONCURRENTLY i2 ON tmp(id3);",
migration,
)
- assert.NilError(t, err)
- assert.Equal(t, migration.Applied, false)
+ checkmate.AssertNil(t, err)
+ checkmate.AssertEqual(t, migration.Applied, false)
}
func TestMigrationDBRepo_ApplyMalformedSql(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration := models.NewTimestampMigration(time.Now(), "test")
err = repo.Apply("this is not SQL", migration)
- assert.ErrorContains(t, err, "syntax error")
- assert.Equal(t, migration.Applied, false)
+ checkmate.AssertErrorContains(t, err, "syntax error")
+ checkmate.AssertEqual(t, migration.Applied, false)
err = repo.Apply("-- bolt: no-transaction\nthis is not SQL", migration)
- assert.ErrorContains(t, err, "syntax error")
- assert.Equal(t, migration.Applied, false)
+ checkmate.AssertErrorContains(t, err, "syntax error")
+ checkmate.AssertEqual(t, migration.Applied, false)
}
func TestMigrationDBRepo_RevertMalformedSql(t *testing.T) {
db := bolttest.NewTestDB(t, "postgres")
repo, err := repositories.NewMigrationDBRepo(db)
- assert.NilError(t, err)
+ checkmate.AssertNil(t, err)
migration := models.NewTimestampMigration(time.Now(), "test")
migration.Applied = true
err = repo.Revert("this is not SQL", migration)
- assert.ErrorContains(t, err, "syntax error")
- assert.Equal(t, migration.Applied, true)
+ checkmate.AssertErrorContains(t, err, "syntax error")
+ checkmate.AssertEqual(t, migration.Applied, true)
err = repo.Revert("-- bolt: no-transaction\nthis is not SQL", migration)
- assert.ErrorContains(t, err, "syntax error")
- assert.Equal(t, migration.Applied, true)
+ checkmate.AssertErrorContains(t, err, "syntax error")
+ checkmate.AssertEqual(t, migration.Applied, true)
}