diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-09 16:15:34 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-09 16:15:34 -0500 |
| commit | 8c4a085cc27eca9966e6f37393c8053fef0c8a1c (patch) | |
| tree | f7b6a45d341e8f503b4338b4ff580a56eb3af872 | |
| parent | Use actions/checkout@v4 (diff) | |
| download | cli-8c4a085cc27eca9966e6f37393c8053fef0c8a1c.zip | |
Cleanup tests
| -rw-r--r-- | internal/bolttest/mock_sql_db.go | 53 | ||||
| -rw-r--r-- | internal/repositories/migration_db_repo.go | 2 | ||||
| -rw-r--r-- | internal/repositories/migration_db_repo_test.go | 60 |
3 files changed, 1 insertions, 114 deletions
diff --git a/internal/bolttest/mock_sql_db.go b/internal/bolttest/mock_sql_db.go deleted file mode 100644 index 0c12592..0000000 --- a/internal/bolttest/mock_sql_db.go +++ /dev/null @@ -1,53 +0,0 @@ -package bolttest - -import "database/sql" - -type MockSqlDb struct { - ExecReturnValue ExecReturnValue - ExecCallCount int - QueryReturnValue QueryReturnValue - QueryCallCount int - QueryRowReturnValue QueryRowReturnValue - QueryRowCallCount int - BeginReturnValue BeginReturnValue - BeginCallCount int -} - -type ExecReturnValue struct { - Result sql.Result - Err error -} - -type QueryReturnValue struct { - Rows *sql.Rows - Err error -} - -type QueryRowReturnValue struct { - Row *sql.Row -} - -type BeginReturnValue struct { - Tx *sql.Tx - Err error -} - -func (db *MockSqlDb) Exec(query string, args ...any) (sql.Result, error) { - db.ExecCallCount += 1 - return db.ExecReturnValue.Result, db.ExecReturnValue.Err -} - -func (db *MockSqlDb) Query(query string, args ...any) (*sql.Rows, error) { - db.QueryCallCount += 1 - return db.QueryReturnValue.Rows, db.QueryReturnValue.Err -} - -func (db *MockSqlDb) QueryRow(query string, args ...any) *sql.Row { - db.QueryRowCallCount += 1 - return db.QueryRowReturnValue.Row -} - -func (db *MockSqlDb) Begin() (*sql.Tx, error) { - db.BeginCallCount += 1 - return db.BeginReturnValue.Tx, db.BeginReturnValue.Err -} diff --git a/internal/repositories/migration_db_repo.go b/internal/repositories/migration_db_repo.go index 8373eda..56bff0c 100644 --- a/internal/repositories/migration_db_repo.go +++ b/internal/repositories/migration_db_repo.go @@ -36,7 +36,7 @@ func NewMigrationDBRepo(db storage.DB) (MigrationDBRepo, error) { `) if err != nil { return nil, fmt.Errorf( - "unable to confirm bolt_migrations database table exists: %w", + "unable to create or confirm bolt_migrations database table exists: %w", err, ) } diff --git a/internal/repositories/migration_db_repo_test.go b/internal/repositories/migration_db_repo_test.go index 0ab6348..b9fb16e 100644 --- a/internal/repositories/migration_db_repo_test.go +++ b/internal/repositories/migration_db_repo_test.go @@ -46,19 +46,6 @@ func TestNewMigrationDBRepo_TableAlreadyExists(t *testing.T) { assert.Equal(t, scanResult, 1) } -// func TestNewMigrationDBRepo_TableCreationErr(t *testing.T) { -// expectedErr := errors.New("error!") -// db := bolttest.MockSqlDb{ -// ExecReturnValue: bolttest.ExecReturnValue{ -// Err: expectedErr, -// }, -// } - -// _, err := repositories.NewMigrationDBRepo(&db) - -// assert.ErrorIs(t, err, expectedErr) -// } - func TestList_EmptyTable(t *testing.T) { db := bolttest.NewTestDB(t) repo, err := repositories.NewMigrationDBRepo(db) @@ -69,21 +56,6 @@ func TestList_EmptyTable(t *testing.T) { assert.Equal(t, len(migrations), 0) } -// func TestList_QueryErr(t *testing.T) { -// expectedErr := errors.New("error!") -// db := bolttest.MockSqlDb{ -// QueryReturnValue: bolttest.QueryReturnValue{ -// Err: expectedErr, -// }, -// } -// repo, err := repositories.NewMigrationDBRepo(&db) -// assert.Nil(t, err) - -// _, err = repo.List() - -// assert.ErrorIs(t, err, expectedErr) -// } - func TestList_SingleResult(t *testing.T) { db := bolttest.NewTestDB(t) repo, err := repositories.NewMigrationDBRepo(db) @@ -180,22 +152,6 @@ func TestApply_MalformedSql(t *testing.T) { assert.Equal(t, migration.Applied, false) } -// func TestApplyWithTx_BeginErr(t *testing.T) { -// expectedErr := errors.New("error!") -// db := bolttest.MockSqlDb{ -// BeginReturnValue: bolttest.BeginReturnValue{ -// Err: expectedErr, -// }, -// } -// repo, err := repositories.NewMigrationDBRepo(&db) -// assert.Nil(t, err) -// migration := models.NewTimestampMigration(time.Now(), "test") - -// err = repo.ApplyWithTx("SELECT 1 FROM bolt_migrations;", migration) - -// assert.ErrorIs(t, err, expectedErr) -// } - func TestApplyWithTx_ExecErr(t *testing.T) { db := bolttest.NewTestDB(t) repo, err := repositories.NewMigrationDBRepo(db) @@ -268,22 +224,6 @@ func TestRevert_MalformedSql(t *testing.T) { assert.Equal(t, migration.Applied, true) } -// func TestRevertWithTx_BeginErr(t *testing.T) { -// expectedErr := errors.New("error!") -// db := bolttest.MockSqlDb{ -// BeginReturnValue: bolttest.BeginReturnValue{ -// Err: expectedErr, -// }, -// } -// repo, err := repositories.NewMigrationDBRepo(&db) -// assert.Nil(t, err) -// migration := models.NewTimestampMigration(time.Now(), "test") - -// err = repo.RevertWithTx("DROP TABLE bolt_migrations;", migration) - -// assert.ErrorIs(t, err, expectedErr) -// } - func TestRevertWithTx_ExecErr(t *testing.T) { db := bolttest.NewTestDB(t) repo, err := repositories.NewMigrationDBRepo(db) |