Skip to content

Commit

Permalink
improve truthy assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Oct 19, 2024
1 parent bbe513d commit 63ab2b4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
56 changes: 28 additions & 28 deletions globals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func TestNewGoMigration(t *testing.T) {
require.Equal(t, m.Next, int64(-1))
require.Equal(t, m.Previous, int64(-1))
require.Equal(t, m.Source, "")
require.True(t, m.UpFnNoTxContext == nil)
require.True(t, m.DownFnNoTxContext == nil)
require.True(t, m.UpFnContext == nil)
require.True(t, m.DownFnContext == nil)
require.True(t, m.UpFn == nil)
require.True(t, m.DownFn == nil)
require.True(t, m.UpFnNoTx == nil)
require.True(t, m.DownFnNoTx == nil)
require.Nil(t, m.UpFnNoTxContext)
require.Nil(t, m.DownFnNoTxContext)
require.Nil(t, m.UpFnContext)
require.Nil(t, m.DownFnContext)
require.Nil(t, m.UpFn)
require.Nil(t, m.DownFn)
require.Nil(t, m.UpFnNoTx)
require.Nil(t, m.DownFnNoTx)
require.True(t, m.goUp != nil)
require.True(t, m.goDown != nil)
require.Equal(t, m.goUp.Mode, TransactionEnabled)
Expand Down Expand Up @@ -149,18 +149,18 @@ func TestLegacyFunctions(t *testing.T) {
m := registeredGoMigrations[1]
assertMigration(t, m, 1)
// Legacy functions.
require.True(t, m.UpFnNoTxContext == nil)
require.True(t, m.DownFnNoTxContext == nil)
require.Nil(t, m.UpFnNoTxContext)
require.Nil(t, m.DownFnNoTxContext)
// Context-aware functions.
require.False(t, m.goUp == nil)
require.False(t, m.UpFnContext == nil)
require.False(t, m.goDown == nil)
require.False(t, m.DownFnContext == nil)
require.NotNil(t, m.goUp)
require.NotNil(t, m.UpFnContext)
require.NotNil(t, m.goDown)
require.NotNil(t, m.DownFnContext)
// Always nil
require.False(t, m.UpFn == nil)
require.False(t, m.DownFn == nil)
require.True(t, m.UpFnNoTx == nil)
require.True(t, m.DownFnNoTx == nil)
require.NotNil(t, m.UpFn)
require.NotNil(t, m.DownFn)
require.Nil(t, m.UpFnNoTx)
require.Nil(t, m.DownFnNoTx)
})
t.Run("all_db", func(t *testing.T) {
t.Cleanup(ResetGlobalMigrations)
Expand All @@ -172,18 +172,18 @@ func TestLegacyFunctions(t *testing.T) {
m := registeredGoMigrations[2]
assertMigration(t, m, 2)
// Legacy functions.
require.False(t, m.UpFnNoTxContext == nil)
require.False(t, m.goUp == nil)
require.False(t, m.DownFnNoTxContext == nil)
require.False(t, m.goDown == nil)
require.NotNil(t, m.UpFnNoTxContext)
require.NotNil(t, m.goUp)
require.NotNil(t, m.DownFnNoTxContext)
require.NotNil(t, m.goDown)
// Context-aware functions.
require.True(t, m.UpFnContext == nil)
require.True(t, m.DownFnContext == nil)
require.Nil(t, m.UpFnContext)
require.Nil(t, m.DownFnContext)
// Always nil
require.True(t, m.UpFn == nil)
require.True(t, m.DownFn == nil)
require.False(t, m.UpFnNoTx == nil)
require.False(t, m.DownFnNoTx == nil)
require.Nil(t, m.UpFn)
require.Nil(t, m.DownFn)
require.NotNil(t, m.UpFnNoTx)
require.NotNil(t, m.DownFnNoTx)
})
}

Expand Down
2 changes: 1 addition & 1 deletion provider_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ func assertResult(t *testing.T, got *goose.MigrationResult, source *goose.Source
require.Equal(t, got.Source, source)
require.Equal(t, got.Direction, direction)
require.Equal(t, got.Empty, isEmpty)
require.True(t, got.Error == nil)
require.Nil(t, got.Error)
require.True(t, got.Duration > 0)
}

Expand Down
64 changes: 32 additions & 32 deletions tests/gomigrations/register/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,48 @@ func checkFunctions(t *testing.T, m *goose.Migration) {
switch filepath.Base(m.Source) {
case "001_addmigration.go":
// With transaction
require.False(t, m.UpFn == nil)
require.False(t, m.DownFn == nil)
require.False(t, m.UpFnContext == nil)
require.False(t, m.DownFnContext == nil)
require.NotNil(t, m.UpFn)
require.NotNil(t, m.DownFn)
require.NotNil(t, m.UpFnContext)
require.NotNil(t, m.DownFnContext)
// No transaction
require.True(t, m.UpFnNoTx == nil)
require.True(t, m.DownFnNoTx == nil)
require.True(t, m.UpFnNoTxContext == nil)
require.True(t, m.DownFnNoTxContext == nil)
require.Nil(t, m.UpFnNoTx)
require.Nil(t, m.DownFnNoTx)
require.Nil(t, m.UpFnNoTxContext)
require.Nil(t, m.DownFnNoTxContext)
case "002_addmigrationnotx.go":
// With transaction
require.True(t, m.UpFn == nil)
require.True(t, m.DownFn == nil)
require.True(t, m.UpFnContext == nil)
require.True(t, m.DownFnContext == nil)
require.Nil(t, m.UpFn)
require.Nil(t, m.DownFn)
require.Nil(t, m.UpFnContext)
require.Nil(t, m.DownFnContext)
// No transaction
require.False(t, m.UpFnNoTx == nil)
require.False(t, m.DownFnNoTx == nil)
require.False(t, m.UpFnNoTxContext == nil)
require.False(t, m.DownFnNoTxContext == nil)
require.NotNil(t, m.UpFnNoTx)
require.NotNil(t, m.DownFnNoTx)
require.NotNil(t, m.UpFnNoTxContext)
require.NotNil(t, m.DownFnNoTxContext)
case "003_addmigrationcontext.go":
// With transaction
require.False(t, m.UpFn == nil)
require.False(t, m.DownFn == nil)
require.False(t, m.UpFnContext == nil)
require.False(t, m.DownFnContext == nil)
require.NotNil(t, m.UpFn)
require.NotNil(t, m.DownFn)
require.NotNil(t, m.UpFnContext)
require.NotNil(t, m.DownFnContext)
// No transaction
require.True(t, m.UpFnNoTx == nil)
require.True(t, m.DownFnNoTx == nil)
require.True(t, m.UpFnNoTxContext == nil)
require.True(t, m.DownFnNoTxContext == nil)
require.Nil(t, m.UpFnNoTx)
require.Nil(t, m.DownFnNoTx)
require.Nil(t, m.UpFnNoTxContext)
require.Nil(t, m.DownFnNoTxContext)
case "004_addmigrationnotxcontext.go":
// With transaction
require.True(t, m.UpFn == nil)
require.True(t, m.DownFn == nil)
require.True(t, m.UpFnContext == nil)
require.True(t, m.DownFnContext == nil)
require.Nil(t, m.UpFn)
require.Nil(t, m.DownFn)
require.Nil(t, m.UpFnContext)
require.Nil(t, m.DownFnContext)
// No transaction
require.False(t, m.UpFnNoTx == nil)
require.False(t, m.DownFnNoTx == nil)
require.False(t, m.UpFnNoTxContext == nil)
require.False(t, m.DownFnNoTxContext == nil)
require.NotNil(t, m.UpFnNoTx)
require.NotNil(t, m.DownFnNoTx)
require.NotNil(t, m.UpFnNoTxContext)
require.NotNil(t, m.DownFnNoTxContext)
default:
t.Fatalf("unexpected migration: %s", filepath.Base(m.Source))
}
Expand Down

0 comments on commit 63ab2b4

Please sign in to comment.