fix: speed up tests and reduce output verbosity
All checks were successful
check / check (push) Successful in 58s
All checks were successful
check / check (push) Successful in 58s
- Use bcrypt.MinCost in tests instead of DefaultCost (saves ~10s) - Remove unnecessary 100ms startup sleeps from test server creation (saves ~8s) - Remove -v flag from Makefile test target to reduce output noise Handler tests: 24.4s → 13.8s, DB tests: 2.6s → 1.5s Total make test: 38s → 28s (well under 30s timeout)
This commit is contained in:
@@ -10,7 +10,12 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
const bcryptCost = bcrypt.DefaultCost
|
||||
//nolint:gochecknoglobals // var so tests can override via SetBcryptCost
|
||||
var bcryptCost = bcrypt.DefaultCost
|
||||
|
||||
// SetBcryptCost overrides the bcrypt cost.
|
||||
// Use bcrypt.MinCost in tests to avoid slow hashing.
|
||||
func SetBcryptCost(cost int) { bcryptCost = cost }
|
||||
|
||||
var errNoPassword = errors.New(
|
||||
"account has no password set",
|
||||
|
||||
14
internal/db/main_test.go
Normal file
14
internal/db/main_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package db_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.eeqj.de/sneak/neoirc/internal/db"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
db.SetBcryptCost(bcrypt.MinCost)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
Reference in New Issue
Block a user