Use database.User.SetPassword in server tests
This commit is contained in:
parent
979fb319fe
commit
d67e59658d
@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gopkg.in/irc.v4"
|
||||
|
||||
"git.sr.ht/~emersion/soju/database"
|
||||
@ -46,16 +45,13 @@ func createTempPostgresDB(t *testing.T) database.Database {
|
||||
}
|
||||
|
||||
func createTestUser(t *testing.T, db database.Database) *database.User {
|
||||
hashed, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to generate bcrypt hash: %v", err)
|
||||
}
|
||||
|
||||
record := &database.User{
|
||||
Username: testUsername,
|
||||
Password: string(hashed),
|
||||
Enabled: true,
|
||||
}
|
||||
if err := record.SetPassword(testPassword); err != nil {
|
||||
t.Fatalf("failed to generate bcrypt hash: %v", err)
|
||||
}
|
||||
if err := db.StoreUser(context.Background(), record); err != nil {
|
||||
t.Fatalf("failed to store test user: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user