Skip to content

Commit

Permalink
test: Disable the logger in MigrateDb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Jan 27, 2025
1 parent fac5639 commit 0bce83e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/init_env/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func setupInitEnvTest() func() {
return nil
}

logger.SetExitOnFatal(false)

return func() {
godotenvLoad = godotenv.Load
logger.SetExitOnFatal(true)
Expand All @@ -36,8 +38,6 @@ func TestInitEnvErrFileNotFound(t *testing.T) {
cleanup := setupInitEnvTest()
defer cleanup()

logger.SetExitOnFatal(false)

Main("bogus")
assert.EqualError(t, godotenvLoad("bogus"), "cannot find the file")
}
11 changes: 6 additions & 5 deletions cmd/migrate_db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ var queryQueryRaw = query.QueryRaw
var queryQueryRow = query.QueryRow
var queryTruncate = query.Truncate
var queryInsert = query.Insert
var loggerInfo = logger.Info
var getFs = func() FS { return content }

func Main(reset bool) error {
var err error

if reset {
logger.Info("Reverting existing migrations")
loggerInfo("Reverting existing migrations")
err = down()

if err != nil {
return err
}
}

logger.Info("Performing migrations")
loggerInfo("Performing migrations")
err = up()

if err != nil {
Expand All @@ -56,7 +57,7 @@ func down() error {
}

if version == 0 {
logger.Info("Nothing to revert")
loggerInfo("Nothing to revert")
return nil
}

Expand All @@ -82,7 +83,7 @@ func down() error {
continue
}

logger.Info("Running migration: %s", name)
loggerInfo("Running migration: %s", name)
err = runMigration(name, migrationIndex)

if err != nil {
Expand Down Expand Up @@ -127,7 +128,7 @@ func up() error {
continue
}

logger.Info("Running migration: %s", name)
loggerInfo("Running migration: %s", name)
err = runMigration(name, migrationIndex)

if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/migrate_db/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/Dobefu/csb/cmd/database/query"
"github.com/Dobefu/csb/cmd/database/structs"
"github.com/Dobefu/csb/cmd/logger"
"github.com/stretchr/testify/assert"
)

Expand All @@ -32,11 +33,14 @@ func setupMigrateDbTest(t *testing.T) (sqlmock.Sqlmock, func()) {
return nil
}

loggerInfo = func(format string, a ...any) string { return "" }

cleanup := func() {
queryQueryRaw = query.QueryRaw
queryQueryRow = query.QueryRow
queryTruncate = query.Truncate
queryInsert = query.Insert
loggerInfo = logger.Info
getFs = func() FS { return content }
}

Expand Down

0 comments on commit 0bce83e

Please sign in to comment.